Created
November 3, 2016 20:48
-
-
Save YoannArasLab/817184c84b7dec9e0dd3105c9d456632 to your computer and use it in GitHub Desktop.
(Aras PLM Server Side Method ) Get Controlled Item when called within a method triggered from a Workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve the workflow item(s) | |
Innovator inn = this.getInnovator(); | |
Item wflItem = this.newItem("Workflow","get"); | |
wflItem.setAttribute("select","source_id,source_type"); | |
Item wflProc = wflItem.createRelatedItem("Workflow Process","get"); | |
wflProc.setAttribute("select","name"); | |
Item wflProcAct = wflProc.createRelationship("Workflow Process Activity","get"); | |
wflProcAct.setAttribute("select","related_id"); | |
wflProcAct.setProperty("related_id",this.getID()); | |
wflItem = wflItem.apply(); | |
if (wflItem.getItemCount() < 1 || wflItem.getItemByIndex(0).getProperty("source_id","").Length != 32 || | |
wflItem.getItemByIndex(0).getPropertyAttribute("source_type","keyed_name","").Length < 1) | |
{ | |
return inn.newError("Error retrieving workflow: " + wflItem.getErrorDetail()); | |
} | |
// Build a list of ids For the versions of the controlled item | |
StringBuilder idList = new StringBuilder(); | |
for (int i=0; i<wflItem.getItemCount(); i++) { | |
if (wflItem.getItemByIndex(i).getProperty("source_type","") != wflItem.getItemByIndex(0).getProperty("source_type","")) | |
{ | |
return inn.newError("Error: Workflow Process attached to items of different types"); | |
} | |
idList.Append("'" + wflItem.getItemByIndex(i).getProperty("source_id","") + "',"); | |
} | |
idList.Remove(idList.Length - 1, 1); | |
// Retrieve the current item controlled by the workflow | |
string contType = wflItem.getItemByIndex(0).getPropertyAttribute("source_type","keyed_name",""); | |
Item contItem = this.newItem(contType,"get"); | |
contItem.setProperty("is_current","1"); | |
contItem.setProperty("id",idList.ToString()); | |
contItem.setPropertyAttribute("id","condition","in"); | |
contItem = contItem.apply(); | |
if (contItem.getItemCount() != 1) return inn.newError("Error retrieving controlled item: " + contItem.getErrorDetail()); | |
return contItem; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment