The ProcessInstance object provides general information about the current Process Instance. These are:
Syntax
public class ProcessInstance
Members
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 time stamp, 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 |
|
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 |
Syntax
public enum ProcessInstanceCallbackType
Members
None = 0 |
Unspecified |
|
UserTaskStarted = 1 |
Indicates that a user task has been started |
|
UserTaskFinished = 2 |
Indicates that a user task has been finished |
|
UserTaskAccepted = 3 |
Indicates that a user task has been accepted |
|
ProcessInstanceFinished = 4 |
Indicates that the process instance has been finished |
|
RolesChanged = 5 |
Indicates that the roles of the process instance have been modified |
|
TaskFinished = 6 |
Indicates that a task has been finished |
|
SubProcessStarted = 7 |
Indicates that the sub process has been started |
|
ProcessInstancePreDelete = 8 |
Indicates that the process instance is about to be deleted |
Method parameters
The method for the callback must have a parameter.
This parameter represents an array that enables access to objects depending on the callback type.
Callback type |
Parameter array |
UserTaskStarted |
[Token, UserTask] |
UserTaskFinished |
[Token, UserTask, User] |
UserTaskAccepted |
[UserTask, User] |
ProcessInstanceFinished |
[ProcessInstance] |
RolesChanged |
[ProcessInstance, string modifiedRoleName] |
TaskFinished |
[Token] |
SubProcessStarted |
[Token, ProcessInstance] |
ProcessInstancePreDelete |
[ProcessInstance, Workflow, User] |
Sample
This sample retrieves the email address of the process instance initiator
mailto = ProcessInstance.Created.Email
This sample 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 sample 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 the callback must have a parameter. 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.