Set workflow activity via action

Hi all,

I was wondering if it was possible to set the workflow activity via an action.

For example, I want a cancel action instead of having multiple vote paths to the cancel activity in a workflow. This would allow a user to cancel the item from any point. This action should set the lifecycle state to Cancelled and the Workflow Activity to Cancelled. Can this be accomplished without a voting path?

  • Just seeing if anyone has any input.

  • Hi mczbas

    It is possible to cancel the item using action and move the life cycle and workflow to cancelled state

    Note: Method is using the path Cancelled (Keep the same name in the life cycle and workflow)

    Create a Method Workflow_Promote

    Innovator inn = this.getInnovator();
    Item wfcItem = inn.newItem(this.getType(), "get");
    wfcItem.setID(this.getID());
    Item workflow = inn.newItem("Workflow", "get");
    Item workflowProcess = inn.newItem("Workflow Process", "get");
    Item wfpa = inn.newItem("Workflow Process Activity", "get");
    Item activity = inn.newItem("Activity", "get");
    activity.setProperty("state", "Active");
    Item activityAssign = inn.newItem("Activity Assignment", "get");
    Item wpp = inn.newItem("Workflow Process Path", "get");
    wpp.setProperty("name", "Cancelled");
    activity.addRelationship(activityAssign);
    activity.addRelationship(wpp);
    wfpa.setRelatedItem(activity);
    workflowProcess.addRelationship(wfpa);
    workflow.setRelatedItem(workflowProcess);
    wfcItem.addRelationship(workflow);
    wfcItem = wfcItem.apply();
    if (wfcItem.isError())
    {
    return inn.newError("Error retrieving Workflow Process Item: " + wfcItem.getErrorString());
    }
    Item wfPaths = wfcItem.getItemsByXPath("//Item[@type='Workflow Process Path']");
    if (wfPaths.getItemCount() != 1)
    {
    return inn.newError("Unable to get the Cancelled Path or Item is already in Cancelled State.");
    }
    string submitPathId = wfPaths.getItemByIndex(0).getID();
    Item act = wfcItem.getItemsByXPath("//Item[@type='Workflow Process Activity']/related_id/Item[@type='Activity']");
    if (act.getItemCount() != 1)
    {
    return inn.newError("Unable to get activity");
    }
    Item actAssign = wfcItem.getItemsByXPath("//Item[@type='Activity Assignment']");
    if (actAssign.getItemCount() != 1)
    {
    return inn.newError("Unable to get activity assignment");
    }
    StringBuilder voteXml = new StringBuilder("");
    voteXml.Append("<Item type=\"Activity\" action=\"EvaluateActivity\">");
    voteXml.Append(" <Activity>{0}</Activity>");
    voteXml.Append(" <ActivityAssignment>{1}</ActivityAssignment>");
    voteXml.Append(" <Paths>");
    voteXml.Append(" <Path id=\"{2}\">Cancelled</Path>");
    voteXml.Append(" </Paths>");
    voteXml.Append(" <DelegateTo>0</DelegateTo>");
    voteXml.Append(" <Tasks />");
    voteXml.Append(" <Variables />");
    voteXml.Append(" <Authentication mode=\"\" />");
    voteXml.Append(" <Comments>Cancelled through Action</Comments>");
    voteXml.Append(" <Complete>1</Complete>");
    voteXml.Append("</Item>");
    Item result = inn.newItem();
    result.loadAML(String.Format(voteXml.ToString(),act.getID(),actAssign.getID(),submitPathId));
    result = result.apply();
    return result;

    Create a Server Action and attach to the item type you want this action

    Create a Transition to Cancel State in Life Cycle

    Create a Path to Cancel State and Update the Promotion in Each State in Workflow

    Demo below. 3 items are in different state (Draft, In Progress and In Review) and Action is allowing to Cancel it.

    Thank You

    Gopikrishnan R

  • Thank you, this is what I was looking for. Implemented perfectly.