ventThis This server-side class provides methods and public functions that allow operating with workflows and theirs components, such as activities, transitions, and other.
To create an instance of the SimpleWorkflow class, follow the example below:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleWorkflow |
---|
linenumbers | true |
---|
|
const simpleWorkflow = new SimpleWorkflow('159491114038814558'); |
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
workflowId | Integer | N | NULL |
cancel(current)
This method allows cancelling all active contexts of the current record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
current | SimpleRecord object | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | cancel |
---|
linenumbers | true |
---|
|
const simpleWorkflow = new SimpleWorkflow('159491114038814558');
if (simpleWorkflow.hasActiveContexts(current)) {
simpleWorkflow.cancel(current);
} |
If a workflow has subflows created for it, use the following script to cancel all contexts of the workflow and any active subflows related to it:
Code Block |
---|
language | js |
---|
theme | Confluence |
---|
title | Example: |
---|
linenumbers | true |
---|
|
const currentDocId = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id);
const wfContext = new SimpleRecord('wf_context');
wfContext.addQuery('related_record_id', currentDocId);
wfContext.addQuery('active', true);
wfContext.orderBy('sys_id');
wfContext.selectAttributes(['workflow_version_id']);
wfContext.query();
const doesActiveWfExist = wfContext.getRowCount() > 0;
while (wfContext.next()) {
const simpleWorkflow = new SimpleWorkflow(wfContext.workflow_version_id.getValue('workflow_id'));
if (simpleWorkflow.hasActiveContexts(current)) {
simpleWorkflow.cancel(current);
}
}
if (doesActiveWfExist) {
ss.addInfoMessage('All contexts have been canceled!');
ss.setRedirect();
} |
copy()
This method copies the workflow with creating a version in the Checked Out state and after that returns a copied workflow.
Return:
Type | Description |
---|
SimpleRecord object or NULL | This method returns NULL if the new SimpleWorkflow object has been created without specifying the workflowId parameter; otherwise, it returns an object of the Workflow (wf_workflow) table (of a SimpleRecord type). |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | copy |
---|
linenumbers | true |
---|
|
const workflow = new SimpleWorkflow('159491114038814558');
const copiedWorkflow = workflow.copy();
const simpleWorkflow = new SimpleWorkflow(copiedWorkflow.sys_id); |
delete()
This method deletes the workflow and all its elements.
Return:
Type | Description |
---|
Boolean | This method returns 'true' if the workflow has been successfully deleted; otherwise, it returns 'false'. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | delete |
---|
linenumbers | true |
---|
|
const simpleWorkflow = new SimpleWorkflow('159491114038814558');
const copiedWorkflow = simpleWorkflow.copy();
const simpleWorkflow = new SimpleWorkflow(copiedWorkflow.sys_id);
if (simpleWorkflow.delete()) {
ss.info('Workflow deleted!');
} |
hasActiveContexts(current)
This method checks the current record if there are any active workflow contexts presented or not.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
current | SimpleRecord object | Y | N |
Return:
Type | Description |
---|
Boolean | This method returns 'true' if the active workflow context presents; otherwise, it returns 'false'. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | hasActiveContext |
---|
linenumbers | true |
---|
|
const simpleWorkflow = new SimpleWorkflow('159491114038814558');
if (simpleWorkflow.hasActiveContexts(current)) {
simpleWorkflow.cancel(current);
} |
revival(executingActivity, current)
This method restarts the workflow starting with the activity specified.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
executingActivity | SimpleRecord object | Y | N |
current | SimpleRecord object | Y | N |
Return:
Type | Description |
---|
SimpleRecord object | This method returns an object of the Workflow Context (wf_context) table (of a SimpleRecord type). |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | revival |
---|
linenumbers | true |
---|
|
const current = new SimpleRecord('task');
current.get('164579976616724057168320271607687220');
const approvalevent = new SimpleRecord('sys_approval'event');
event.addQuery('name', 'workflow_timer');
event.addQuery('instance', current.sys_id);
approvalevent.getaddQuery('164625329711023536''state', 'ready');
event.query();
event.next();
const executingActivity = new SimpleRecord('wf_executing_activity');
executingActivity.get(approval.getValue('wf_executing_activity_id'));
const workflowevent.param_1);
const simpleWorkflow = new SimpleWorkflow();
workflowsimpleWorkflow.revival(executingActivity, current); |
start(current)
Use this method to start the workflow. The method starts only the workflows where the Condition Type is set to Manual.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
current | SimpleRecord object | Y | N |
Return:
Type | Description |
---|
SimpleRecord object or NULL | This method returns NULL in the cases listed below: - the new SimpleWorkflow object has been created without specifying the workflowId parameter;
- there are no workflow versions created by the current user.
Otherwise, it returns an object of the Workflow Context (wf_context) table (of a SimpleRecord type). |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | start |
---|
linenumbers | true |
---|
|
const simpleWorkflow = new SimpleWorkflow('159491114038814558');
const context = simpleWorkflow.start(current);
if (context.state === 'finished') {
ss.info('Workflow finished!');
} |
startSubflow(executingActivity, current, workflowId)
This method allows starting a sub-workflow by executing activity.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
executingActivity | SimpleRecord object | Y | N |
current | SimpleRecord object | Y | N |
workflowId | Integer | Y | N |
Return:
Type | Description |
---|
SimpleRecord object or NULL | This method returns NULL if there are no workflow versions created by the current user; otherwise, it returns an object of the Workflow Context (wf_context) table (of a SimpleRecord type). |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | startSubflow |
---|
linenumbers | true |
---|
|
;
(
(current, activity) => {
const wfActivitySubflow = new SimpleRecord('wf_activity_subflow');
wfActivitySubflow.get(activity.getValue('activity_id'));
const workflowManager = new SimpleWorkflow();
const subflowContext = workflowManager.startSubflow(activity, current, wfActivitySubflow.getValue('workflow_id'));
ss.info(subflowContext.state);
// Info: executing
}
)(current, activity); |