Merge Process Instances

API Type

Web Services


Merges 2 or more process instances into one process instance.

Good to Know

  • These process instances must be based on the same process model.
  • If more than one process instance is intended to perform the same operation, instead of having more than one process instance, you can merge all the process instances into a single process instance.
  • To call this method, the API account user must have the access right, Cancel a Process.
  • This method is provided for reference for very advanced users — mainly internal AgilePoint teams. If you need help with this method, contact AgilePoint Professional Services.


public virtual string MergeProcInsts(WFProcessMergingInstruction instruction)


Name Description


Specifies the instructions for merging two process instances.
Accepted Values:
A WFProcessMergingInstruction object.


The process instance ID of the merged process instance.


string MergeProcessInstances(IWFWorkflowService svc, string[]
    IWFWorkflowService svc = GetWorkflowService();

    // suspends all of process instances to be merged.
    foreach (string id in processInstanceIDs)

    // query process instances
    string inExpr = ShUtil.Merge(processInstanceIDs, true);
    WFQueryExpr queryExpr = new WFQueryExpr("PROC_INST_ID", SQLExpr.IN,
    WFAny.Create(inExpr), true);
    WFBaseProcessInstance[] pis = svc.QueryProcInsts(queryExpr);

    // merge custom attributes
    NameValue[] mergedCustomAttributes = GetMergeCustomAttributes(api, pis);
    string procInstID = UUID.GetID();
    string procInstName = pis[0].DefName + "_" + DateTime.Now.Tostring()
    + " - Merged";
    string workObjectID = procInstID + " - Merged";
    WFProcessMergingInstruction instruction = new
    instruction.MergingProcessInstanceIDs = processInstanceIDs;
    instruction.MergedProcessInstance = new
    return svc.MergeProcInsts(instruction);

// sample code for merging custom attributes
private NameValue[] GetMergeCustomAttributes(IWFWorkflowService svc,
WFBaseProcessInstance[] pis)
    List<string> workObjectIDs = new List<string>();
    foreach (WFBaseProcessInstance pi in pis)
    KeyValue[] items = svc.GetCustomAttrsEx(workObjectIDs.ToArray());
    Dictionary<string, System.Xml.XmlDocument> dss =
    new Dictionary<string, System.Xml.XmlDocument>();
    foreach (KeyValue item in items)
        WFCustomAttributes ds = new WFCustomAttributes();
        ds.AttrXml = item.Value;
        System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
        xmlDoc.LoadXml(ds["//"] as string);
        dss[item.Key] = xmlDoc;
    // master processInstanceID and workObjectID
    string masterProcessInstanceID = pis[0].ProcInstID;
    string masterWorkObjectID = pis[0].WorkObjectID;
    System.Xml.XmlDocument masterXmlDoc = dss[masterWorkObjectID];
    System.Xml.XmlNamespaceManager nsm =
    System.Xml.XmlNode titleNode =
    masterXmlDoc.SelectSingleNode("/pd:issueTracking/pd:issueTitle", nsm);
    titleNode.InnerText = "Title - Merged";
    System.Xml.XmlNode descriptionNode =
    masterXmlDoc.SelectSingleNode("/pd:issueTracking/pd:description", nsm);
    descriptionNode.InnerText = "Description - Merged";
    System.Xml.XmlNode parent =
    masterXmlDoc.SelectSingleNode("/pd:issueTracking/pd:Persons", nsm);
    // merge rest of children
    foreach (string key in dss.Keys)
        if (key == masterWorkObjectID) continue;
        System.Xml.XmlDocument secondaryXmlDoc = dss[key];
        System.Xml.XmlNamespaceManager nsmgr =
        System.Xml.XmlNode node =
        secondaryXmlDoc.SelectSingleNode("/pd:issueTracking/pd:Persons", nsmgr);
        parent.InnerXml += node.InnerXml;
    return NameValue.Array("//", masterXmlDoc.OuterXml);


Supported Versions

4.5 and higher

Code Examples in the AgilePoint NX Documentation

The AgilePoint NX Product Documentation is intended as a basic reference to help you understand how to complete basic coding tasks, such as make API or JavaScript method calls. Code examples that show specific use cases, the solutions to specific business problems, or detailed implementation scenarios are outside the scope of the AgilePoint NX Product Documentation. For specific and/or advanced types of examples that may better meet your requirements, AgilePoint provides several resources:

  • AgilePoint Community Forums - A free, AgilePoint-moderated, crowd-sourcing user forum where you can ask questions about specific techniques, the solutions to use cases, workarounds, or other topics that may not be covered in the Product Documentation.
  • Professional Services - If you can not find the information you need for your specific business problem, mentoring is available through AgilePoint Professional Services.
  • Personalized Training - AgilePoint can provide personalized training for your organization. To request personalized training, contact AgilePoint Sales.