- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 05:47 AM
Hi All,
I have a if workflow activity which will return yes or no based on scratchpad variable. but, unfortunately for one request the scratchpad variable is assigned with wrong value and it is creating odd results, so is there anyway to change the value in scratchpad variable using scripts so that the workflow will follow correct path after the update.
Thanks and regards'
Swamy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 06:48 AM
i have used below script to update scratchpad variables and it worked.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id','');
gr.query();
while(gr.next())
{
var wf = new Workflow().getRunningFlows(gr);
while(wf.next()) {
//new Workflow().broadcastEvent(wf.sys_id, 'pause');
wf.scratchpad.i = '23';
wf.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 05:51 AM
The short answer is yes, you can update the workflow scratchpad through scripts. Use a workflow activity Run Script and put the server side code in there as you wish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 05:53 AM
Hi Chuck,
Thank you !!
but, i want to update for workflow whcih is already triggered so i have to update in a context.
Regards
Swamy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 06:02 AM
I tried the below script but it is returning undefined value.
var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id','cf22e51b6ff5be802f29e9e44b3ee42f');
gr.query();
while(gr.next())
{
var workflow = new Workflow();
var context = workflow.getContexts(gr);
//make sure we have a valid context
if (context.next()) {
var msg = context.scratchpad.i;
gs.print(msg);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2017 06:05 AM
Thank you Swamy. I think I understand.
You've got active contexts that are running and want to update the workflow scratchpad so the workflow will change how it is being processed. Good question. I don't believe there is an external way to impact the internal variables of a workflow once it is running. I'll defer to someone more knowledgable about the internals of workflows though.