update scratchpad variable through script

amaradiswamy
Kilo Sage

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

1 ACCEPTED SOLUTION

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();


                  }




}


View solution in original post

7 REPLIES 7

Chuck Tomasi
Tera Patron

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.



Run Script workflow activity


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


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);



}


}


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.