Workflow Process Get Change ItemType

Good day all.  I have a Method to dynamically assign a drafter to the activity.  Currently I have to specify the ItemType of the change I am using for this method to work, meaning I would have to recreate the Method for each different kind of change ItemType I want to use this on.  How can I pull the associated change ItemType from the Workflow Process or Workflow Process Activity that the method is running from to make this a more generic method?  The Method is written in C#.  Thank you for your help.

Parents
  • // Called OnActivate from the Work Request activity of sm_NDR. This will assign the drafter selected by the Drafting Lead.

    Innovator inn = this.getInnovator();
    string actId = this.getID();

    // Retrieve the workflow item
    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.getProperty("source_id","").Length != 32 || wflItem.getPropertyAttribute("source_type","keyed_name","").Length < 1)
    {
    return inn.newError("Error retrieving workflow: "+wflItem.getErrorDetail());
    }

    //GET the Drafter from the NDR
    Item ecoParent = this.newItem("sm_NDR", "get");
    ecoParent.setID(wflItem.getProperty("source_id"));
    ecoParent.setAttribute("select","drafter");
    ecoParent=ecoParent.apply();

    bool permissionWasSet = false;
    Aras.Server.Security.Identity transIdentity = Aras.Server.Security.Identity.GetByName("Aras PLM");

    try
    {
    permissionWasSet = Aras.Server.Security.Permissions.GrantIdentity(transIdentity);


    //GET the Identity from the User
    Item ecoDrafter = this.newItem("User","get");
    ecoDrafter.setID(ecoParent.getProperty("drafter"));
    ecoDrafter.setAttribute("select","owned_by_id");
    ecoDrafter=ecoDrafter.apply();

    Item getAssignment = this.newItem("Activity Assignment", "get");
    getAssignment.setProperty("source_id", actId);
    getAssignment.setAttribute("select", "id");
    getAssignment = getAssignment.apply();


    // This deletes the Identities for the Activity if the Workflow had to be stepped backwards (i.e. rework the document)
    if(!getAssignment.isError())
    {
    for (int i = 0; i < getAssignment.getItemCount(); i++)
    {
    var assignmentId = getAssignment.getItemByIndex(i).getID();
    Item removeAssignment = this.newItem("Activity Assignment", "delete");
    removeAssignment.setAttribute("id", assignmentId);
    removeAssignment.setAttribute("doGetItem", "0");
    removeAssignment = removeAssignment.apply();
    if(removeAssignment.isError())
    {
    return inn.newError("Error removing assignment: "+removeAssignment.getErrorDetail());
    }
    }
    }

    // Add the Drafter to the Activity Assignment
    Item assignment = this.newItem("Activity Assignment", "");
    assignment.setAction("add");
    assignment.setPropertyAttribute("locked_by_id","is_null","1");
    assignment.setProperty("source_id", this.getID());

    string drafter = ecoDrafter.getProperty("owned_by_id"); // Get Drafter Identity ID
    assignment.setProperty("related_id", drafter);
    assignment.setProperty("voting_weight", "100");
    Item result = assignment.apply();
    if (result.isError())
    {
    return inn.newError("Workflow Assignment: Error adding assignment: " + result.getErrorDetail());
    }

    }

    finally
    {
    if (permissionWasSet)
    {
    Aras.Server.Security.Permissions.RevokeIdentity(transIdentity);
    }
    }
    return this;

  • Happy to see that there are also other users that offer rework possibilities in their Change Management processes. 

    Regarding your questions: The easiest way to get the top ItemType would be to use the 'labs_GetControlledItemCSharp' Method. With this Method you don´t have to go through all the Workflow and Assignment relationships by yourself and it´s highly reusable:

    Item controlledItem = this.newItem(this.getAttribute("type"), "labs_GetControlledItemCSharp");
    controlledItem.setID(this.getID());
    controlledItem = controlledItem.apply();
    string cmType = controlledItem.getAttribute("type");

    Of course the Method is also a good reference when you want to do the query by yourself. You should find it somewhere in the Aras Labs github website.

Reply
  • Happy to see that there are also other users that offer rework possibilities in their Change Management processes. 

    Regarding your questions: The easiest way to get the top ItemType would be to use the 'labs_GetControlledItemCSharp' Method. With this Method you don´t have to go through all the Workflow and Assignment relationships by yourself and it´s highly reusable:

    Item controlledItem = this.newItem(this.getAttribute("type"), "labs_GetControlledItemCSharp");
    controlledItem.setID(this.getID());
    controlledItem = controlledItem.apply();
    string cmType = controlledItem.getAttribute("type");

    Of course the Method is also a good reference when you want to do the query by yourself. You should find it somewhere in the Aras Labs github website.

Children