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 - Lifecycle Pre/Post and AML Questions

Nick - Monday, April 25, 2011 9:52 AM:

So I'm working on more ECR and federated (not together though) related tasks, but I figured this would be more general. I noticed that if you put a method on the post area of the first node in a lifecycle, the item the lifecycle is tied to doesn't seem to exist yet. 

I'll be a little more specific, I'm trying to check an ECR state when a new item is added. Instead of having multiple methods, one for when the ECR is created, one for each state and one for when an item is added or updated, I have all the code in one method. Because of this, I use an if statement to generate a value:

tmpHist.setProperty("ec_state", ((this.getProperty("state" == "New") ? "Pending" : "In Review"));

Although this code works in other places, when it's run during post ECR creation the ecr property state doesn't seem to exist yet. Does pre/post not work the same as before/after does? I figured because it's a post it's run after the item is created.

 

My other question is just related to how AML is set up, just so I fully understand it myself. I was wondering if someone could write the AML for building the relationship from Part to Part AML to Manufacturer Part to Manufacturer, I'm a little confused as to how you define which property is linked between items.

 

qryManu.loadAML(

"<Item type='Part' action='get' select='id,is_current'>" +

"<id condition='eq'>" + this.getID() + "</id>" +

"<Relationships>" + 

"<Item type='Part AML' action='get' select='source_id,related_id(id)'>" +

"<related_id>" +

"<Item type='Manufacturer Part' action='get' select='name,id,manufacturer(name)'>" +

"<manufacturer>" +

"<Item type='Manufacturer' action='get' select='name,id'>" +

"</Item>" +

"</manufacturer>" +

"</Item>" +

"</related_id>" +

"</Item>" +

"</Relationships>" +

"</Item>"

);

this is my attempt at it, but it doesn't seem to link it property. 

 



Brian - Wednesday, April 27, 2011 7:30 AM:

Hi Nick,

I'm not going to try to answer the first question right now.

But this is the AML for the second (you are really close)

<Item type="Part" action="get" select="id,name,item_number">
<item_number>1234567</item_number>
<Relationships>
<Item type="Part AML" action="get" select="related_id">
<related_id>
<Item type="Manufacturer Part" action="get" select="manufacturer,item_number">
<manufacturer>
<Item type="Manufacturer" action="get"/>
</manufacturer>
</Item>
</related_id>
</Item>
</Relationships>
</Item>

Cheers,

Brian.



Nick - Thursday, April 28, 2011 11:46 AM:

Thanks for the response Brian, 

So if I understand this correctly, I don't need to specify what related id links to (I was doing related_id(id)) and either use <Relationships> or the actual related property to link things together? also, what exactly does putting something in brackets do? (ie: manufacturer(name))

Also, if I'm understanding this correctly, this is basically the AML code that running these commands would form?

Item rPart = newItem("part", "get");

rPart.setAttribute("select", "id,name,item_number");

rPart.setProperty("item_number", "1234567");

Item rPartAML = rPart.createRelatedItem("Part AML", "get");

rPartAML.setAttribute("select", "related_id");

Item rManuPart = rPartAML.createRelatedItem("Manufacturer Part", "get");

rManuPart.setAttribute("select", "manufacturer,item_number");

Item rManu = rManuPart.createRelatedItem("Manufacturer", "get");

rPart = rPart.apply();

would that code create the same relationship? Just want to try and understand both ways to create one.



Brian - Saturday, April 30, 2011 8:45 AM:

Hi Nick,

The brackets in the AML are a shortcut to retrieve the properties of the property in question. You can write the full AML or you can write "related_id(id)"

You use the full AML if you want to go deeper into the relationship hierarchy. You can use the short cut if you want to reduce the amount of AML you are writing.

The code you have should produce the same AML. The easiest way to see is to enable the just in time debugger and examine the XML or you could just set up a dummy method that returns the xml from rPart and display it in an alert or window.

Cheers,

Brian.