Dynamic workflow, set assigned id based on drop down list

オフライン

Hi,

I am new with C#

I am trying to read an ECO form drop down list value (manufsites) and then based on that add corresponding identity as assigned.

I can without the IF statement set the identities as assigned,
but when try to read my drop down list value it does not work,

any ideas, please help

my code:

// Called OnActivate from activities in the Simple Change workflow. Adds assignments to
// the activity based on the Owner or Manager of affected items

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());
}

Item q = this.newItem();
q.loadAML("<Item type='Activity Assignment' action='get' select='id'><source_id>"+this.getAttribute("id")+"</source_id></Item>");
q = q.apply();
if (q.getItemCount()>0) return this;//The activity is reactivated.

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 manufsite from the manufs drop down list ------------

string ManufSit = wflItem.getProperty("manufsites");


if (ManufSit== "aaaa")

//IF I remove the IF row above, then below Identity is set correctly (note fictive values in this example)

{
string identId = "xxxxxxxxxxxx";
Item assignment = this.newItem("Activity Assignment", "");
assignment.setAction("add");
assignment.setProperty("source_id", actId);
assignment.setPropertyAttribute("locked_by_id","is_null","1");
assignment.setProperty("related_id",identId);
assignment.setProperty("voting_weight", "50");
assignment.setProperty("is_required", "1");
assignment = assignment.apply();
if (assignment.getItemCount() != 1) return inn.newError("Error creating assignment: "+assignment.getErrorDetail());

}



if (ManufSit== "bbbb")
{
string identId = "yyyyyyyyyyy";
Item assignment = this.newItem("Activity Assignment", "");
assignment.setAction("add");
assignment.setProperty("source_id", actId);
assignment.setPropertyAttribute("locked_by_id","is_null","1");
assignment.setProperty("related_id",identId);
assignment.setProperty("voting_weight", "50");
assignment.setProperty("is_required", "1");
assignment = assignment.apply();
if (assignment.getItemCount() != 1) return inn.newError("Error creating assignment: "+assignment.getErrorDetail());

}



}

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

Parents
  • Hi

    Are you able to get these value "ManufSit" or is it empty ? Try below code and let me know if you still face issues

    // Called OnActivate from activities in the Simple Change workflow. Adds assignments to
    // the activity based on the Owner or Manager of affected items

    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());
    }

    Item q = this.newItem();
    q.loadAML("<Item type='Activity Assignment' action='get' select='id'><source_id>"+this.getAttribute("id")+"</source_id></Item>");
    q = q.apply();
    if (q.getItemCount()>0) return this;//The activity is reactivated.

    Item ecoParent = this.newItem("Simple ECO", "get");
    ecoParent.setID(wflItem.getProperty("source_id"));
    ecoParent.setAttribute("select","manufsites");
    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 manufsite from the manufs drop down list ------------

    string ManufSit = ecoParent.getProperty("manufsites");


    if (ManufSit== "aaaa")

    //IF I remove the IF row above, then below Identity is set correctly (note fictive values in this example)

    {
    string identId = "xxxxxxxxxxxx";
    Item assignment = this.newItem("Activity Assignment", "");
    assignment.setAction("add");
    assignment.setProperty("source_id", actId);
    assignment.setPropertyAttribute("locked_by_id","is_null","1");
    assignment.setProperty("related_id",identId);
    assignment.setProperty("voting_weight", "50");
    assignment.setProperty("is_required", "1");
    assignment = assignment.apply();
    if (assignment.getItemCount() != 1) return inn.newError("Error creating assignment: "+assignment.getErrorDetail());

    }

    if (ManufSit== "bbbb")
    {
    string identId = "yyyyyyyyyyy";
    Item assignment = this.newItem("Activity Assignment", "");
    assignment.setAction("add");
    assignment.setProperty("source_id", actId);
    assignment.setPropertyAttribute("locked_by_id","is_null","1");
    assignment.setProperty("related_id",identId);
    assignment.setProperty("voting_weight", "50");
    assignment.setProperty("is_required", "1");
    assignment = assignment.apply();
    if (assignment.getItemCount() != 1) return inn.newError("Error creating assignment: "+assignment.getErrorDetail());

    }

    }

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

  • オフライン in reply to Gopikrishnan

    Thanks Gopikrishnan, it worked perfectly!!

    Do you know if it is possible by method to remove/reset the assigned identity?

    Let's say user selected wrong in the drop down list, and AA was set instead of BB
    Then in next step user AA rejects it and we then want to change AA to BB

    But when looking in the flow, AA is still set

    So is it possible to reset next assigned ID before code above executes, so  thew new choice BB gets assigned in next step?

    thanks//Mikael

  • オフライン in reply to mkalla

    Hi Mikael

    Try below code and let me know if it helps. Include bold text in your method.

    // Called OnActivate from activities in the Simple Change workflow. Adds assignments to
    // the activity based on the Owner or Manager of affected items

    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());
    }

    Item q = this.newItem();
    q.loadAML("<Item type='Activity Assignment' action='get' select='id'><source_id>"+this.getAttribute("id")+"</source_id></Item>");
    q = q.apply();
    if (q.getItemCount()>0) return this;//The activity is reactivated.

    Item ecoParent = this.newItem("Simple ECO", "get");
    ecoParent.setID(wflItem.getProperty("source_id"));
    ecoParent.setAttribute("select","manufsites");
    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 manufsite from the manufs drop down list ------------

    string ManufSit = ecoParent.getProperty("manufsites");

    Item getAssignment = this.newItem("Activity Assignment", "get");
    getAssignment.setProperty("source_id", actId);
    getAssignment.setAttribute("select", "id");
    getAssignment = getAssignment.apply();
    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());
    }
    }
    }

    if (ManufSit== "aaaa")

    //IF I remove the IF row above, then below Identity is set correctly (note fictive values in this example)

    {
    string identId = "xxxxxxxxxxxx";
    Item assignment = this.newItem("Activity Assignment", "");
    assignment.setAction("add");
    assignment.setProperty("source_id", actId);
    assignment.setPropertyAttribute("locked_by_id","is_null","1");
    assignment.setProperty("related_id",identId);
    assignment.setProperty("voting_weight", "50");
    assignment.setProperty("is_required", "1");
    assignment = assignment.apply();
    if (assignment.getItemCount() != 1) return inn.newError("Error creating assignment: "+assignment.getErrorDetail());

    }

    if (ManufSit== "bbbb")
    {
    string identId = "yyyyyyyyyyy";
    Item assignment = this.newItem("Activity Assignment", "");
    assignment.setAction("add");
    assignment.setProperty("source_id", actId);
    assignment.setPropertyAttribute("locked_by_id","is_null","1");
    assignment.setProperty("related_id",identId);
    assignment.setProperty("voting_weight", "50");
    assignment.setProperty("is_required", "1");
    assignment = assignment.apply();
    if (assignment.getItemCount() != 1) return inn.newError("Error creating assignment: "+assignment.getErrorDetail());

    }

    }

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

    Thank You

    Gopikrishnan R

  • オフライン in reply to Gopikrishnan

    Hi, no it did not work

    I selected "AA" and AA was assigned when I sent it to activity "Review" (= correct)
    AA then rejected ECO and then I unlocked it, changed AA to BB in the form, then sent it to Review again and AA was still set as assigned.

    //Mikael

  • オフライン in reply to mkalla

    Hi 

    Can you confirm where this method is attached in workflow?. Also can you share the workflow screenshot

  • オフライン in reply to mkalla

    I quickly tested and it seems to be working in my local instance. Can you confirm the identity id hard coded in method xxxxx and yyyyyy are different? 

    Also if only one assignment is there, then I guess voting weight should be 100 instead of 50 in your method

  • オフライン in reply to Gopikrishnan

    yes the id's are different
    string identId = "32456085EDC34925930C2B5559ACEEB4";

    ...

    string identId = "0D2D86D4654B4304965A74572373791E";

    I also tried hard code one of the assigned id's in the remove string

    removeAssignment.setAttribute("id", "0D2D86D4654B4304965A74572373791E");

    but did not work either, the id was still assigned in the Review stage

    Regarding voting weight, I just updated the method to set weight correctly
    One selected = 100
    Two selected = 50 each

  • オフライン in reply to mkalla

    could it be Permission related?

    Even if I login as admin, root, ... any ID..
    I can't change/ delete assigned in the workflow, the icons are greyed out

  • オフライン in reply to mkalla

    Hi Mikael

    Try removing below lines in your method and give a try

    Item q = this.newItem();
    q.loadAML("<Item type='Activity Assignment' action='get' select='id'><source_id>" + this.getAttribute("id") + "</source_id></Item>");
    q = q.apply();
    if (q.getItemCount() > 0) return this; //The activity is reactivated.

    It should work as per my knowledge.

    Thank You

    Gopikrishnan R

  • オフライン in reply to Gopikrishnan

    Hi Gopikrishnan

    YES it worked, thanks a lot for all your help

    Regards
    //Mikael

Reply Children
No Data