Unable to get workflow scratchpad value in catalog tasks.

Souvik Das1
Giga Contributor

I have used run script to retrieve a value from a catalog task and store it in workflow scratchpad. Then I have used the Advanced section of catalog tasks to populate a field value with the scratchpad value. In some of the tasks I can see the value being populated but after a few tasks the field value is not populating from workflow scratchpad. Why is this happening I can't understand. 

This is the run script to retrieve value and store it in the scratchpad.

var ritm_sys_id = current.getValue('sys_id');
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery('short_description=Test Task 1^request_item=' + ritm_sys_id);
gr.query();
if (gr.next()) {
	workflow.scratchpad.choice = gr.u_choice;
}

And this is the script written in the advanced section of the catalog tasks.

task.u_choice = workflow.scratchpad.choice;
7 REPLIES 7

Hey, I have provided the code. Please check once.

Hi Souvik,

I have gone through your script. So for this value to get populated the below condition should work every time.

gr.addEncodedQuery('short_description=Test Task 1^request_item=' + ritm_sys_id);

 

So my question to you, have you checked the short_description of tasks? Is it same as 'Test Task 1'? If yes then it should work else not.

Plus this script will only work for future records you will create using the catalog item and not for the past records.

 

Please mark this as correct and helpful if it resolved the query or lead you in right direction.

Thanks,
Mohit Kaushik
Community Rising Star 2022

Thanks,
Mohit Kaushik
ServiceNow MVP (2023-2025)

Souvik Das1
Giga Contributor

I have added the scripts. Please check once.