How to get the workflow of a change item programmatically?

Hi, I want to run the following client code from an Express ECO button event:
var innovator = new Innovator(); 

var thisItem = document.thisItem;
var id = thisItem.getID(); // id of Express ECO

// here should be the code that fetches the Workflow Process id.

var qryItem = innovator.newItem(); 
qryItem.loadAML( 
"<Item type='Workflow Process' id='/*----missing ID----*/' initial_action='get' action='do_l10n' select='state, name,related_id(name)' >" +
              "<Relationships>" +
                "<Item type='Workflow Process Activity' action='get' select='related_id'>"+
                  "<related_id>" +
                  "<Item type='Activity' action='get' select='name,related_id(name)'>" +
                    "<state condition='ne'>Pending</state>" +
                    "<Relationships>" +
                      "<Item type='Activity Assignment' action='get' select='related_id' >" +
                         "<related_id type='Identity' select='keyed_name' />" +
                      "</Item>" +
                    "</Relationships>" +
                  "</Item>" +
                  "</related_id>" +
                "</Item>" +
              "</Relationships>" +
            "</Item>"
); 
var resultItem = qryItem.apply(); 
Unfortunately I wan´t able to find the missing link between the Express ECO and the corresponding Workflow Process yet. Can you give me a hint how the two are connected? Thanks again! Angela
Parents
  • Hi Mahmoud, thanks for your example! I was able to read the ID with your code instantly. I've always searched inside the WorkflowProcess ItemType for the missing link, but I didn´t notice the Workflow ItemType. Here it is even described with an "you cannot overlook it" image - which of course I have overlooked: community.aras.com/.../ But maybe someone can help me here: I want to avoid the use of multible queries for getting all needed information. So integrated the Workflow query into my regular code. Querying the Workflow Process id now works, but I cannot read my other values anymore:
    var innovator = new Innovator(); 
    
    var thisItem = document.thisItem;
    var id = thisItem.getID(); // id of CM item
    var type = thisItem.GetType(); // Type of CM item, e.g. Express ECO
    
    var workflow = innovator.newItem("Workflow","get"); 
    workflow.setProperty("source_id", id);
    // workflow.setProperty("source_type", "CBA93BEFFB4F499CAF122CB79E204983"); // Express ECO
    workflow.setAttribute("select", "state, name, related_id(name)"); 
    
    var workflowProcess = workflow.createRelatedItem("Workflow Process","get"); 
    workflowProcess.setAttribute("select", "name, id"); 
    
    var workflowProcessActivity = workflowProcess.createRelationship("Workflow Process Activity","get"); 
    workflowProcessActivity.setAttribute("select", "related_id");
    
    var activity = workflowProcessActivity.createRelatedItem("Activity", "get"); 
    activity.setPropertyCondition("state", "ne");
    activity.setProperty("state", "Pending");
    activity.setAttribute("select", "name,related_id(name)");
    
    var activityAssignment = activity.createRelationship("Activity Assignment", "get");
    activityAssignment.setAttribute("select", "id, related_id");
    
    var identity = activityAssignment.createRelatedItem("Identity", "get");
    identity.setAttribute("select", "keyed_name"); 
    
    workflow = workflow.apply(); 
    var wfpID = workflow.getItemByIndex(0).getProperty("related_id"); // Workflow Process ID - works!
    var act = workflowProcessActivity.getItemByIndex(0).getProperty("related_id"); // don´t work, returns undefined
    
    alert(wfpID + " " + act);
    What could be missing? (I converted the "staircase" AML query into a flat hierarchy. For me this structure is easier to use, but that's a personal habit.)
Reply
  • Hi Mahmoud, thanks for your example! I was able to read the ID with your code instantly. I've always searched inside the WorkflowProcess ItemType for the missing link, but I didn´t notice the Workflow ItemType. Here it is even described with an "you cannot overlook it" image - which of course I have overlooked: community.aras.com/.../ But maybe someone can help me here: I want to avoid the use of multible queries for getting all needed information. So integrated the Workflow query into my regular code. Querying the Workflow Process id now works, but I cannot read my other values anymore:
    var innovator = new Innovator(); 
    
    var thisItem = document.thisItem;
    var id = thisItem.getID(); // id of CM item
    var type = thisItem.GetType(); // Type of CM item, e.g. Express ECO
    
    var workflow = innovator.newItem("Workflow","get"); 
    workflow.setProperty("source_id", id);
    // workflow.setProperty("source_type", "CBA93BEFFB4F499CAF122CB79E204983"); // Express ECO
    workflow.setAttribute("select", "state, name, related_id(name)"); 
    
    var workflowProcess = workflow.createRelatedItem("Workflow Process","get"); 
    workflowProcess.setAttribute("select", "name, id"); 
    
    var workflowProcessActivity = workflowProcess.createRelationship("Workflow Process Activity","get"); 
    workflowProcessActivity.setAttribute("select", "related_id");
    
    var activity = workflowProcessActivity.createRelatedItem("Activity", "get"); 
    activity.setPropertyCondition("state", "ne");
    activity.setProperty("state", "Pending");
    activity.setAttribute("select", "name,related_id(name)");
    
    var activityAssignment = activity.createRelationship("Activity Assignment", "get");
    activityAssignment.setAttribute("select", "id, related_id");
    
    var identity = activityAssignment.createRelatedItem("Identity", "get");
    identity.setAttribute("select", "keyed_name"); 
    
    workflow = workflow.apply(); 
    var wfpID = workflow.getItemByIndex(0).getProperty("related_id"); // Workflow Process ID - works!
    var act = workflowProcessActivity.getItemByIndex(0).getProperty("related_id"); // don´t work, returns undefined
    
    alert(wfpID + " " + act);
    What could be missing? (I converted the "staircase" AML query into a flat hierarchy. For me this structure is easier to use, but that's a personal habit.)
Children
No Data