Split Process Instance

API Type

Web Services

Description

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

Syntax

public virtual string[] SplitProcInst(WFProcessSplittingInstruction instruction)

Parameters

Name Description

instruction

Definition:
Specifies the instructions for splitting a process instance.
Type
WFProcessSplitting
Allowed 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