Split Process Instance

API Type

Web Services

Description

Splits one process instance into 2 or more process instances. The original process instance is canceled.

Syntax

public virtual string[] SplitProcInst(WFProcessSplittingInstruction instruction)

Parameters

Name Description

instruction

Function:
Specifies the instructions for splitting a process instance.
Type
WFProcessSplitting
Accepted Values:
A WFProcessSplitting object.

Output

A collection of strings that contain the process instance IDs for the process instances that were created from the split.

Example

// This is console application sample
public string[] SplitProcessInstance(string processInstanceID)
	{
    IWFWorkflowService svc = GetWorkflowService();
    WFBaseProcessInstance processInstance =
    svc.GetProcInst(processInstanceID);
    WFCustomAttributes ds = ds = new
    WFCustomAttributes(processInstance.WorkObjectID);
    ds.AttrXml = svc.GetCustomAttrs(processInstance.WorkObjectID);
    string xml = ds["//"] as string;
    Console.WriteLine("Splitting custom attributes ...");
    List<NameValue[]> splittedCustomAttributes =
    GetSplittedCustomAttributes(xml);
    WFProcessSplittingInstruction instruction;
    instruction = new WFProcessSplittingInstruction();
    instruction.SplittingProcessInstanceID = procInstID;
    List<string> workObjectIDs = new List<string>();
    for (int i = 0; i < splittedCustomAttributes.Count; ++i)
        {
        string SplittingProcessInstanceID = UUID.GetID();
        string splittedProcInstName = string.Format("{0} – Splitted -
	    {1}", pi.ProcInstName, i + 1);      
        string splittedWorkObjectID = string.Format("{0} – Splitted -
	    {1}", pi.WorkObjectID, i + 1);
        instruction.Add(
        SplittingProcessInstanceID,
        splittedProcInstName,
        splittedWorkObjectID,
        null,      
        splittedCustomAttributes[i]);
        }
    instruction.Validate();
    Console.WriteLine("Suspending process instance...");
    svc.SuspendProcInst(procInstID);
    System.Threading.Thread.Sleep(1000);
    string[] ids = svc.SplitProcInst(instruction);
    return ids;
	}

// function to split custom attributes
private List<NameValue[]> GetSplittedCustomAttributes(string xml)
	{
    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
    xmlDoc.PreserveWhitespace = true; xmlDoc.LoadXml(xml);
    System.Xml.XmlNamespaceManager nsm = ShUtil.GetNamespaces(xmlDoc);
    System.Xml.XmlNode parent =
    xmlDoc.SelectSingleNode("/pd:issueTracking/pd:Persons", nsm);

    // split repeating notes – 'pd:issueTracking/pd:Persons/pd:Person'
    System.Xml.XmlNodeList nodes = parent.SelectNodes("pd:Person", nsm);

    if (nodes == null || nodes.Count < 2)
	   {
       throw new InvalidOperationException("Failed to get splitted
       customAttributes,
             'pd:issueTracking/pd:Persons/pd:Person' does not have
       multiple node.");
	   }

    // remove child nodes
    System.Xml.XmlNode titleNode =
    xmlDoc.SelectSingleNode("/pd:issueTracking/pd:issueTitle", nsm);
    string title = titleNode.InnerText;
    System.Xml.XmlNode descriptionNode =
    xmlDoc.SelectSingleNode("/pd:issueTracking/pd:description", nsm);
    string description = descriptionNode.InnerText;
    List<NameValue[]> splittedCustomAttributes = new
    List<NameValue[]>();
    for( int i = 0; i < nodes.Count; ++i)
	   {
       //change title
       titleNode.InnerText = title + "-Splitted-" + i;
       descriptionNode.InnerText = description + "- Splitted-" + i;
       parent.RemoveAll();
       parent.AppendChild(nodes[i]);
       splittedCustomAttributes.Add( NameValue.Array("//",
       xmlDoc.OuterXml) );
	   }
    return splittedCustomAttributes;
	}

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.