Versions Compared

Key

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

This server-side class provide methods and public functions that allow operating with workflows and theirs components, such as activities, transitions, and so on.

You can create an instance of the SimpleWorkflow class in the way described below:


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

Parameter(s):

NameTypeMandatoryDefault Value
workflowIdStringNNULL

cancel(current)


This method allows cancelling all active contexts of the current record.


Parameter(s):

NameTypeMandatoryDefault 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 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 method copies the workflow with creating a version in the Checked Out state and after that returns a copied workflow.


Return:

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


Example:

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

delete()


This method deletes the workflow and all its elements.


Return:

TypeDescription
BooleanThis method returns the boolean result (TRUE if the workflow was successful successfully deleted; otherwise, returns FALSE).


Example:

Code Block
languagejs
themeEclipse
titledelete
linenumberstrue
const simpleWorkflow =  	letnew SimpleWorkflow('159491114038814558');
const copiedWorkflow = simpleWorkflow.copy();
   	letconst 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 present or not.


Parameter(s):

NameTypeMandatoryDefault Value
currentSimplerecord SimpleRecord objectYN


Return:

TypeDescription
BooleanThis method returns the boolean result (TRUE if the active workflow context presents; otherwise, returns FALSE).


Example:

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

revival(executingActivity, current)


This public function restarts method restarts the workflow starting with the activity specified.


Parameter(s):

NameTypeMandatoryDefault Value
executingActivitySimplerecord SimpleRecord objectYN
currentSimplerecord SimpleRecord objectYN


Return:

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


Example:

Code Block
languagejs
themeEclipse
titlerevival
linenumberstrue
letconst current = new SimpleRecord('task');
current.query(get('164579976616724057');
const approval = new SimpleRecord('sys_approval');
currentapproval.nextget('164625329711023536');
letconst activityexecutingActivity = new SimpleRecord('wf_executing_activity');
activityexecutingActivity.query();
activity.next();
let contextget(approval.getValue('wf_executing_activity_id'));

const workflow = (new SimpleWorkflow())->revival(activity;
workflow.revival(executingActivity, current);

start(current)


This method is intended to start the workflow. The method starts only the workflows where the Condition Type is set to Manual.


Parameter(s):

NameTypeMandatoryDefault Value
currentSimpleRecord objectYN


Return:

TypeDescription
SimpleRecord object or NULL

This method returns NULL

if

in the cases listed below:

  • the new SimpleWorkflow object has been created without specifying the workflowId parameter;
otherwise
  • there are no workflow versions created by the current user.

Otherwise, it returns an object of the

SimpleRecord object

Workflow Context (wf_context) table (of a SimpleRecord type)


Example:

Code Block
languagejs
themeEclipse
titlestart
linenumberstrue
const simpleWorkflow =  letnew SimpleWorkflow('159491114038814558');
const context = simpleWorkflow.start(current);
    if (context.state === 'finished') {
    	ss.info('Workflow finished!');
    }


startSubflow(executingActivity, current, workflowId)


This public function allows method allows starting sub-workflow by executing activity.


Parameter(s):

NameTypeMandatoryDefault Value
executingActivitySimpleRecord objectYN
currentSimpleRecord objectYN
workflowIdIntegerStringYN


Return:

TypeDescription
SimpleRecord object or NULLThis method returns NULL is if there are no workflow versions created by the current user; otherwise, it returns an object of the SimpleRecord object. Workflow Context (wf_context) table (of a SimpleRecord type). 


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