Get WF State programmatically

Hello all I have a problem to get the state of Workflow of an Item. I can get the state of lifecycle but do not know how to get the WF-State? Any hint which can help me?   Thanks Mahmoud
  • replace {itemID} with the id of your Item Item wfObj = this.getInnovator().newItem("Workflow", "get"); wfObj.setAttribute("select", "keyed_name, source_type(name, keyed_name), source_id,related_id(*)"); wfObj.setProperty("source_id", {itemID}); wfObj = wfObj.apply(); Item wfpObj = (!wfObj .isError()) ? wfObj .getRelatedItem() : null;  
  • Thanks Zahar, It seems but I can not get the name of that state. See Image https://imgur.com/a/nPbNX In this case I want to get the "technical review" when if the workflow reach this state. If I go from Workflow --> Workflow process--> Workflow activity --> Activity I can see the texts but in the Workflow process I am not sure how can I set the filter to get back the only active process or activity. Am I missing something here?   Kind Regards Mahmoud
  • Hello Mahmoud, If I understand your question now, is how to get active activities (in Aras you can have more that one Active activities) and not the state value of the Workflow? So lets update the code:
    string aml = @"
     <AML>
       <Item type='Workflow' action='get'>
         <source_id>{itemID}</source_id>
         <related_id>
           <Item type='Workflow Process' action='get'>
             <Relationships>
               <Item action='get' type='Workflow Process Activity'>
                 <related_id>
                   <Item type='Activity'>
                     <cloned_as condition='is null' />
                     <state>Active</state>
                   </Item>
                 </related_id>
               </Item>
             </Relationships>
           </Item>
         </related_id>
       </Item>
     </AML>";
    
    Item workflowItem = this.getInnovator().applyAML(aml);
    if (workflowItem != null && !workflowItem.getItemCount() > 0) {
      Item activeActivities = workflowItem.getItemsByXPath("//Item[@type='Activity']");
      for (int i = 0; i < activeActivities.getItemCount(); i++) {
        Item activeActivity = activeActivities.getItemByIndex(i);
        string activeActivityName = activeActivity.getProperty("name", "");
      }
    }