Retrieve all variables from Record Producers in a workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2016 05:50 AM
We use ServiceNow for Case Management. Mostly questions and problems, but users can also request a service.
These requests are generated via Record Producers.
I set up some workflows, and found it difficult that there is no clear link between the variables in Record Producers and the workflow.
So I set up the following script right after the beginning of the workflow:
var gr = new GlideRecord('question_answer');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('question.type', 'NOT IN', '12,20,24,19,11,14,17');
gr.query();
while(gr.next()) {
workflow.scratchpad[gr.question.name] = gr.value;
workflow.info(gr.question.name + ' : ' + gr.value);
};
With this, I have access to all the variables from the Record Producer that I can use to add conditions and other scripts to the workflow.
UPDATE
I took me too long, but I finally solved the bug in this script. Take away: do not ever name the label of a field 'value' or something similar that is used in scripts.
Feel free to give a good explanation in the comments, but I think the script above did not put a value in the scratchpad variables, but a pointer to an ever changing variable. That's why in the end all my scratchpad variables had the same value: the value of the last record in the query.
So, what does work is:
var gr = new GlideRecord('question_answer');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('question.type', 'NOT IN', '12,20,24,19,11,14,17');
gr.query();
while(gr.next()) {
workflow.scratchpad[gr.question.name] = gr.getValue('value');
workflow.info(gr.question.name + ' : ' + workflow.scratchpad[gr.question.name]);
};
getValue of value. This shouldn't be.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-28-2017 08:44 AM
Jan,
Can you tell me how I would go about referencing that value in my workflow then? I am trying to retrieve the value of one of the record producer variables in an approval task, but the result is always returns "skipped." The workflow activity log does capture the values, but I cannot seem to grab the value in my script. Any help would be greatly appreciated.
Best regards,
Theresa

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2018 10:40 AM