Modifying a workflow scratchpad outside of a workflow

Have you ever found yourself encountering a problem mid-way through running a lengthy, complex workflow? Perhaps some value was referenced incorrectly or there was some kind of typo in the data? It would be preferable to be able to do something about it without having to start from scratch! The following method was developed to update a workflow that has reached an error state.

The workflow that prompted the creation of this script had stopped and created a task, but some data was incorrect. We were then able to to update the scratchpad values via this script. We then closed the task and the workflow automatically re-ran the failed step with the new values in place. Potentially, over an hour of time was saved!

 

//Start with a GlideRecord of the record the workflow is attached to

var scRITM = new GlideRecord('sc_req_item');

scRITM.get('fbb0d7dadb5dcf00af529c94db9619b1'); //Get a specific record (a request item in this case)



//Get the workflow script object ready

var workflow = new Workflow();



//Get all workflow contexts for your GlideRecord

var context = workflow.getContexts(scRITM);



//This returns a GlideRecord like list of contexts to iterate through.

//The 'workflow' field can be tested to see which workflow the context is for.

if (context.next()) {

	

	//Access the scratchpad variables using context.scratchpad.(variable_name)

	context.scratchpad.location = 'My Location';



	//Then update the context to save your changes

	context.update();

}

Check out a virtual demo: