Type parameters
Hierarchy
- BaseItem<ProcessInstanceData>
- ItemRef<ProcessInstanceItem<Context>>
-
ProcessInstanceItemRef<Context>
- ProcessInstanceItem
Properties
__id
Instance ID.
Readonly code
App code of the URL’s target (the app’s code).
Readonly data
Values of object’s fields.
Readonly fields
Description of the object’s fields.
Readonly id
ID of the URL’s target.
Readonly namespace
Namespace of the URL target (the code of the workspace that the app belongs to).
Methods
fetch
-
Request complete data of a reference object.
Returns Promise<ProcessInstanceItem<Context>>
getParent
-
The method returns the parent process instance.
It is possible to run subprocesses within other processes in the company. When you work with a subprocess, you can get the parent process that the subprocess was started from.
const parentProcess = await instance.getParent();
Returns Promise<ProcessInstanceItem<Context> | undefined>
The parent process if it exists.
getTemplate
-
The method returns the template of the process.
The method gets the template that was used to create the process instance. The template contains context fields. These fields and their types need to be taken into account when starting a process or working with the current process instance’s fields. For example, fields that reference an app may contain the app’s Namespace and code. In the example below, the
application
field in the process context stores a link to thecontracts
app in thedocuments
workspace. This information allows us to get access to the app via Namespace.// instance is the variable that stores the launched process const template = await instance. getTemplate(); // We extract the field that the app is linked with from the template const applicationField = template.context['application']; if (!applicationField) { throw new Error('App field not found'); } // After extracting the app, you can run search in it, create app items, etc. const app = Namespace.app[applicationField.data. code];
Returns Promise<ProcessTemplate<Context>>
Process template.
getTimer
-
The method returns an active timer in a process.
The method returns an instance of an active timer using the ID of the BPMN activity that the timer is set in. You can copy the activity’s ID from the address bar when you open the Timer’s settings. It’s a regular UUID written as a string. If the process hasn’t come to the timer yet or has already moved past it, the method will return
undefined
.// `instance` is a variable containing the running process instance const timer = await instance.getTimer('BPMN activity ID'); if (timer) { // An active timer has been found, so we can perform further operations with it }
Parameters
-
timerOwnerId: string
ID of the activity that the timer is set in.
Returns Promise<ProcessTimer | undefined>
An active timer if it is started.
-
getTimers
-
The method returns all active timers in a process.
The method returns an array of active timer instances. If there are no active timers in the process instance at the time the method is executed, an empty array will be returned.
// `instance` is a variable containing a running process instance const timers = await instance. getTimers();
Returns Promise<ProcessTimer[]>
Active timers.
interrupt
-
The method is used to interrupt a process instance.
If a process instance is completed or if it is currently executing an activity, the method throws an exception. The example shows how the process is interrupted if there is an error in the
someError
field in the context.if (Context.data.someError !== '') { try { await process.interrupt(Context.data.someError) } catch (e) { // The process has already finished, so the exception is processed } }
Parameters
-
comment: string
Reason for interrupting the process instance.
Returns Promise<void>
-
normalize
-
Delete duplicate data in arrays.
The method deletes duplicates in fields that store arrays of links to system objects (users, files, app items, or documents). For example, you can call this method after bulk editing data within an object.
const app1 = await Context.data.app1.fetch(); const app2 = await Context.data.app2 .fetch(); app1.data.executors.push(app2.data.executors); app1.normalize(); // Now we need to go over the elements in the new array app1.data.executors .forEach( ... );
Returns void
setResponsible
-
This method allows you to change the user responsible for the process instance.
In this example, we are changing the responsible employee using the context data:
user
is a field of the User type.comment
is a String written to the context.const user = Context.data. newResponsible; const comment = Context.data.comment; await processInstance .setResponsible(user, comment);
Parameters
-
responsible: UserItemRef
Link to a user.
-
Optional comment: undefined | string
Reason for changing the responsible user.
Returns Promise<void>
updateContext
-
The method is used to edit the process instance’s context.
If a process instance is completed or if it is currently executing an activity, the method throws an exception. If the method is executed successfully, the process context is changed, and no exception is thrown.
In the example, the context contains a contract number received from an external source, for example, using a request. The method allows passing the retrieved number into the context of a different process.async function updateContext(): Promise<void> { try { // Getting the contract number from the context const contractNumber = Context.data.contructid // Writing the `newprocess` process to the `processTemplate` variable const processTemplate = Application. processes.incomecontract; // Getting the ID of the process instance from the process context const instanceUUID = Context.data. instanceUUID; // Searching for a process instance const process = await processTemplate._searchInstances().where(x => x.__id. eq(instanceUUID)).first(); // Getting a comment for updating from the process context const comment = Context.data.comment; // New value of the Contract number field const context = {contract: contractNumber}; // Updating context await process?. updateContext(context, comment); } catch (e) { // The process has already started, so the exception is processed } }
Parameters
-
context: Context
New process instance context.
-
comment: string
Reason for changing the process instance context. Required parameter. You cannot pass an empty string in it.
Returns Promise<void>
-
Process instance object