This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - How best to initiate a method during a lifecycle transition for which an Aras method is already defined

PoliKarpas - Tuesday, May 6, 2014 1:24 PM:

Greetings!

I am trying to figure out how to define a Pre server method that will be initiated as any change ItemType (ECN, Simple ECO, Express ECO) is promoted to Released. The current lifecycle maps for each of these ItemTypes already has "PE_ChangeItemTransition" method defined for this state transition, and there does not seem to be a way to extend this list beyond one method. The method I am writing will export the given change to ERP. If successful, I would want the state transition to complete, whereas if the export to ERP fails for some reason, I would want the state transition to fail.

The issue I have is not being able to extend the list of methods executed as the change is being promoted to Released. If this list can be extended, I also would like to specify the order by which the methods at that state transition are executed.

I would think this feature of multiple methods being executed at any state transition for any ItemType would be applicable for any number of reasons, and hence, should be considered as a global Aras feature.



gks - Friday, May 9, 2014 2:48 AM:

Make a method that calls all the other methods. and use this method in the transition.



PoliKarpas - Friday, May 9, 2014 11:40 AM:

Thanks Georg, but I was hoping for a configurable feature ... not adding maintenance-required additional code. I am trying to create a generic application (ERP Connector) applicable for any customer - not just a one-of solution. Other PLM systems I have supported provide such a configurable trigger mechanism - one able to support any number of triggers within a single state-transition.



Brian - Sunday, May 11, 2014 9:47 PM:

Hi PoliKarpas,

This is a bit round-about but you could still do what you want as a configurable item.

Create an item type called "Trigger collection" that just has to have a name and a lifecyle and maybe lifecycle state to trigger on.

Create a relationship either a null relationship or a normal relationship if you want to use the "trigger" again. Call this null relationship or target item type "Triggers". In triggers include a "Method" item type as a property.

Create a single server method called "Execute Triggers" and have it retrieve the LIfecycle information from when it is called and retrieve the "Trigger Collection" appropriate to this lifecycle.

Now execute the server methods, evaluate the results and return as appropriate to the lifecycle to advance/fail the transition.

Once you have set the framework up you won't have to write any more code and can call an unlimited number of methods on transition.

I did a similar thing to execute multiple queries on data and output to a formatted report.

Hope this helps,

Brian.

 



PoliKarpas - Tuesday, May 20, 2014 3:17 PM:

Bryan, thanks for the reply and recommendation. However, I am a little unsure about part of your recommendation. 

You first wrote: "Create a relationship either a null relationship or a normal relationship if you want to use the "trigger" again.If we were to create a normal relationship (I assume you mean one that has a source and target item type), I assume its Source Item Type would be "Trigger Collection". What would be its Related Item Type?

You then wrote: "In Triggers include a 'Method' item type as a property." Not sure what you mean by 'Method' Item Type. The property Data Type list does not include Method as a choice.

You also wrote: "Now execute the server methods...". What/Whose server method?

If you could please create an easy diagram of all of the related elements of your recommended solution, I would be MOST grateful.

Sincerely, Linas



Brian - Tuesday, May 20, 2014 10:05 PM:

Hi Linas,

OK. Step by step.

Create an item type called "Trigger Collection". Add properties to it: "name" = type string length 64. "lifecycle_transition" = type Item, source = "Life cycle transition"

Create an item type called "Trigger". Add properties to it: name = type string length 64, "method" = type Item, source "Method"

Create a relationship from Trigger Collection to Trigger. Name Trigger Collection Trigger.

Create a method: Server side. C#. Name = "Execute Triggers"

Paste this code into:

// Called from lifecycle transitions.

// Retrieve "Trigger Collection" that corresponds to this lifecycle.

// Execute all methods associated with this colleciton.

 

//System.Diagnostics.Debugger.Break();

 

Innovator inn = this.getInnovator();

 

string transitionId = this.getProperty("transition","");

if ( string.IsNullOrEmpty(transitionId) ){

return this;

}

 

Item trigColl = inn.newItem("Trigger Collection","get");

trigColl.setProperty("lifecycle_transition",transitionId);

 

Item trigRel = inn.newItem("Trigger Collection Trigger","get");

 

Item triggers = inn.newItem("Trigger","get");

 

trigRel.setRelatedItem(triggers);

trigColl.addRelationship(trigRel);

 

trigColl = trigColl.apply();

 

Item trigs = trigColl.getItemsByXPath("//Item[@type='Trigger']");

string body = this.dom.InnerXml;

for ( int i = 0; i < trigs.getItemCount(); i++){

string methodId = trigs.getItemByIndex(i).getProperty("method");

Item meth = inn.newItem("Method","get");

meth.setID(methodId);

meth.setAttribute("select","id,name");

meth = meth.apply();

string methName = meth.getProperty("name");

Item result = inn.applyMethod(methName,body);

if ( result.isError() ){

return result;

}

}

 

return this;

 

Create a "Trigger Collection" item. Call it "Trigger Collection 1"

Select a lifecycle transition to have this trigger on.

Create a "Trigger" item and within that item select a Method to execute.

Save it all.

Add the method "Execute Triggers" to the lifecycle transition that you selected for the Trigger Collection item.

Now promote an item through this lifecycle state and the "trigger" should be called and the nominated server method executed.

To test this I created an Item type called "Junk" with one property - Name.

I gave this a lifecycle with three states and transitions between the states with a Role of World and associated the Trigger Collection with one of the lifecycle transitions.

Create a "Junk" item and promote it through its lifecycle. The server methods in the "Triggers" are called on only one of the lifecycle transitions.

If you are still having problems with this please send me an email direct to [email protected] and I can more easily include pictures or other attachments that will help.

Hope this helps,

Brian.