Can you safely store a GlideRecord object in a workflow scratchpad variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 07:15 PM
If I have a workflow script activity that is running a GlideRecord query, can I safely store that GlideRecord object in a scratchpad variable, and access it again in a subsequent activity if I need to get another element? Example:
in Workflow Step 1:
var user_sys_id = '<placeholder>'
var user_gr = new GlideRecord('sys_user');
workflow.scratchpad.user = user_gr.get(user_sys_id);
~~~stuff happens~~~~
in Workflow Step 7:
var user_email = workflow.scratchpad.user.email;
I'm looking into an issue where a workflow seems to sometimes return '{ }' when accessing an element of a GlideRecord stored in the scratchpad. Trying to narrow things down - not sure if this is outright wrong, not best practice, or totally fine, and something else might be going on. Thanks!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 07:51 PM
Hi Cori,
If you see in step 7 you did .email in fetching value from step 1.
Fetch email in step 1 only.
Best Regards,
Prashant
If my answer helped you in any way, please mark this answer as helpful and correct.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 08:17 PM
Thanks, but I'm trying to understand what happens to the GlideRecord if I do this. Is it overwritten in memory? Should I never store a GlideRecord object in a scratchpad variable? It seems to work more often than not so I'd really like to understand what's happening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2022 08:21 PM
Hi Cori,
You can do that there is no problem because it will be available only in workflow scope.
Best Regards,
Prashant
If my answer helped you in any way, please mark this answer as helpful and correct.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2022 02:02 PM
When you put something on the scratch pad the system will eventually do a JSON.stringify() on the scratchpad object and store it in a string field on the workflow context record. So with that said a GlideRecord object does not really stringify. You best bet is to just store the sys_id of the record and then later in the workflow when you need it query for it at that point.
So if you have a script activity and then several activities later you have another one and you need the User info you will most probably have to get the record again for that activities script.