Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This server-side class provides methods and public functions that allow operating operate with workflows and theirs components, such as activities, transitions, and other.

To create an instance of the SimpleWorkflow class, follow pass the workflow ID as in the example below:

Code Block
languagejs
themeEclipse
titleSimpleWorkflow
linenumberstrue
const simpleWorkflow = new SimpleWorkflow('159491114038814558');

Parameter(s):

NameTypeMandatoryDefault Valuevalue
workflowIdIntegerStringNNULLnull

cancel(current)


This method allows cancelling all active Use this method to cancel all active contexts of the current record.

Parameter(s):

NameTypeMandatoryDefault
Value
value
currentSimpleRecord objectYN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

Code Block
languagejs
themeEclipse
titlecancel
linenumberstrue
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 all subflows related to it:

Code Block
languagejs
themeConfluence
titleExample:
linenumberstrue
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 Use this method copies to copy the workflow with creating . The system creates a version of the in the Checked Outout state and , after that the method returns a the copied workflow.

Return:

TypeDescription
SimpleRecord object
or NULL
This method returns
NULL
null if the new SimpleWorkflow object
 has
has been created without
specifying
the workflowId
 parameter
parameter specified; otherwise, it returns
an
a SimpleRecord object of the Workflow (wf_workflow)
table (of a SimpleRecord type)
table.

Example:

Code Block
languagejs
themeEclipse
titlecopy
linenumberstrue
const workflow = new SimpleWorkflow('159491114038814558');
const copiedWorkflow = workflow.copy();
const simpleWorkflow = new SimpleWorkflow(copiedWorkflow.sys_id);

delete()


This Use this method deletes to delete the workflow and all its elements.

Return:

TypeDescription
BooleanThis method returns
'
true
'
if the workflow has been successfully deleted; otherwise, it returns
'
false
'
.

Example:

Code Block
languagejs
themeEclipse
titledelete
linenumberstrue
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 Use this method checks to check the current record if there are for any active workflow contexts presented or not.

Parameter(s):

NameTypeMandatoryDefault
Value
value
currentSimpleRecord objectYN

Return:

TypeDescription
BooleanThis method returns
'
true
' if
if the active workflow context
presents
exits; otherwise, it returns
'
false
'
.

Example:

Code Block
languagejs
themeEclipse
titlehasActiveContext
linenumberstrue
const simpleWorkflow = new SimpleWorkflow('159491114038814558');
if (simpleWorkflow.hasActiveContexts(current)) {
	simpleWorkflow.cancel(current);
}

revival(executingActivity, current)


Use this method to restart the workflow for the specified record.

Info

This

method restarts

method only works when the workflow

starting with

context and the

activity specified

required activity are not in the Finished state. Add this condition to your scripts when this method is used.

Parameter(s):

NameTypeMandatoryDefault
Value
value
executingActivitySimpleRecord objectYN
currentSimpleRecord objectYN

Return:

TypeDescription
SimpleRecord objectThis method returns an SimpleRecord object of the Workflow Context (wf_context) table
(of a SimpleRecord type)
.

Example:

Code Block
languagejs
themeEclipse
titlerevival
linenumberstrue
const current = new SimpleRecord('task');
current.get('168320271607687220164579976616724057');

const eventapproval = new SimpleRecord('sys_eventapproval');
eventapproval.addQueryget('name', 'workflow_timer164625329711023536');

const executingActivity = new SimpleRecord('wf_executing_activity');
event.addQuery('instance', current.sys_id);
event.addQuery('state', 'ready');
event.query();
event.next();

const executingActivity = new SimpleRecord('wf_executing_activity');
executingActivity.get(event.param_1);
const simpleWorkflowexecutingActivity.get(approval.getValue('wf_executing_activity_id'));

const context = new SimpleRecord('wf_context');
context.get(executingActivity.getValue('context_id'));
if (context.getValue('state') == 'finished' || executingActivity.getValue('state') == 'finished') {
  ss.info(`Revival for executing activity ${executingActivity.sys_id} and current ${current.getTableName()}:${current.sys_id} is not called because executing activity or context is already finished`);
} else { 
  const workflow = new SimpleWorkflow();
simpleWorkflow  workflow.revival(executingActivity, current);
}

start(current)


Use this method to start the workflow. The method only starts only the workflows where with the Condition Type is type set to Manual.

Parameter(s):

NameTypeMandatoryDefault
Value
value
currentSimpleRecord objectYN

Return:

TypeDescription
SimpleRecord object
SimpleRecord object or NULL

The method returns a SimpleRecord object of the Workflow Context (wf_context) table. 

This method returns

NULL

null in the following cases

listed below

:

  • the new SimpleWorkflow
object has
  • object has been created without specifying the workflowId
 parameter;
  • 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
languagejs
themeEclipse
titlestart
linenumberstrue
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 Use this method to start a subflow by executing activity.

Parameter(s):

NameTypeMandatoryDefault
Value
value
executingActivitySimpleRecord objectYN
currentSimpleRecord objectYN
workflowId
Integer
StringYN

Return:

TypeDescription
SimpleRecord object
or NULL

This method returns

NULL if there are no workflow versions created by the current user; otherwise, it returns an

a SimpleRecord object of the Workflow Context (wf_context) table

(of a SimpleRecord type)

It returns null if there are no workflow versions created by the current user.

Example:

Code Block
languagejs
themeEclipse
titlestartSubflow
linenumberstrue
;
(
  (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);


Table of Contents
absoluteUrltrue
classfixedPosition