Skip to content

Instantly share code, notes, and snippets.

@YoannArasLab
Created February 22, 2018 08:06
Show Gist options
  • Save YoannArasLab/f67e03c02c183d6fd558c22173d2348d to your computer and use it in GitHub Desktop.
Save YoannArasLab/f67e03c02c183d6fd558c22173d2348d to your computer and use it in GitHub Desktop.
[Aras] Updates a polysource item to get the properties existing on the polyitemtype
// Get innovator ref
Innovator inn = this.getInnovator();
// Init new properties created boolean
Boolean hasNewProperties = false;
// retrieve the Poly-itemtype
Item polyItemType = inn.getItemById("ItemType", this.getProperty("source_id"));
// retrieve MorphaeItemType
Item MorphaeItemType = this.newItem("ItemType","get");
MorphaeItemType.setID(this.getProperty("related_id"));
MorphaeItemType.apply();
MorphaeItemType.fetchRelationships("Property");
// test if the itemtype is a polyitemtype (should be useless as the method is ran on a Morphae Add Event)
if (polyItemType.getProperty("implementation_type") == "polymorphic"){
// get polyitem custom properties
polyItemType.fetchRelationships("Property");
Item polyItemTypeProperties = polyItemType.getRelationships("Property");
// for each source - check if the property exists (if yes, check that it has the same format, if no add it)
for (int i = 0; i < polyItemTypeProperties.getItemCount(); i++)
{
//test if property exists and if it is different from "itemtype"
if ((MorphaeItemType.getRelationships("Property").getItemsByXPath("//Item[name='" + polyItemTypeProperties.getItemByIndex(i).getProperty("name") + "']").getItemCount() < 1) & (polyItemTypeProperties.getItemByIndex(i).getProperty("name") != "itemtype")){
// clone the found property
Item distributedProperty = polyItemTypeProperties.getItemByIndex(i).clone(false);
// Add the Property
MorphaeItemType.addRelationship(distributedProperty);
// activate the morphae update
hasNewProperties = true;
}
}
if (hasNewProperties){
// set edit action
MorphaeItemType.setAction("edit");
// Perform the query.
Item results = MorphaeItemType.apply();
}
}
return this;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment