ProcessInstance

public class ProcessInstance

The ProcessInstance object provides general information about the current Process Instance.

 Properties

int Id

The Id of the process instance

Guid GuId

The GuId of the process instance

string Name

The Name of the process instance

DateTime CreatedAt

The timestamp when the process instance has been created

User Created

This attribute contains all attributes of the initiator of the process instance. If the process instance has been created anonymously, this attribute will be null.

Roles Roles

A list of roles that have been defined in the process context

Events Events

A list of events in the process instance context

string Details

Gets or sets process instance details that are displayed in the overview of running instances

 Methods

byte[] ReadFileBytes(string filename)

Read the bytes of a process instance file into a byte array

Stream ReadFileToStream(string filename)

Read a process instance file into a stream

void WriteFileBytes(string filename, byte[] bytes)

Write the bytes of a byte array to a process instance file

void WriteFileFromMemoryStream(string filename, System.IO.MemoryStream mem)

Write the content of a memory stream to a process instance file

void GetFileUrl(string filename)

Get the URL required to download a process instance file

void Warn(string message)

Append a warning into the process instance log

void Info(string message)

Append an information to the process instance log

void Error(string message)

Append an error to the process instance log
CAUTION: This will force the process instance to halt in error state

void RegisterCallback(ProcessInstanceCallbackType callbackType, string script, string method)

Register a callback on certain event types.

object GetWorkflowAttribute(string name)

Retrieves a workflow attribute from the instance even if it has not been imported

void SetWorkflowAttribute(string name, object value)

Stores a workflow attribute in the instance even if it has not been imported

string GetFileUrl(string filename)

Retrieve the URL to a file

string GetRepositoryFileUrl(string relativefilename)

Retrieves the repository file url of the given relative file name. The path must be relative based on the workflow file

void TriggerRolesChanged(IEnumerable<string> rolenames)

Method triggers the roles changed event

DataSet GetRootDataSet()

Get the record of the root dataset

DataSet GetCurrentDataSet()

Get the current dataset

Events LoadAllProcessEvents()

Get the events of the process instance

Examples

This example retrieves the email address of the process instance initiator.

mailto = ProcessInstance.Created.Email

This example modifies the content of a word document. The variable myfile points to a file which may either be uploaded from a web form or which could be retrieved out of a data store.

import clr
clr.AddReferenceToFileAndPath(Session.GetAdapterPath("IYOPRO.WORD"))
from IYOPRO.WORD import *

data = ProcessInstance.ReadFileBytes(myfile)
with Adapter() as word:
    word.SetDocumentBytes(data)
    word.ReplaceBookmark('MyBookMark','Hello World')
    stream = word.GetDocumentStream()
    ProcessInstance.WriteFileFromMemoryStream(myfile,stream)

This example registers a callback every time, a user has accepted a user task.

ProcessInstance.RegisterCallback(ProcessInstanceCallbackType.UserTaskAccepted,"MyBPIScript.py","UserAccepted")

The method that you implement for this callback must have a parameter (ProcessInstanceCallbackType). This parameter represents an array that enables access to UserTask and User (for UserAccepted(args) it would be args[0] for UserTask and args[1] for User).
You could use the method, for example, to record which task was accepted by whom. You could also find out for which tasks the person working on them is constantly changing.

Likewise, you could protocol with UserTaskFinished which tasks were finished by whom.
Or ProcessInstancePreDelete could be used so that if someone tries to delete a process instance, it is checked in advance whether certain requirements are met before this process instance is actually deleted.