Populating ServiceNow variable through the Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 01:26 AM
I have a Workflow script, that is assigning values to different variables. Below is that script:
I have created a new variable Approval to Hire ID, and I want to assign this value also. I've written the below line but that's not working:
grReqItem.variables.u_approval_to_hire_id = current.variables.u_approval_to_hire_id;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 04:27 AM
yes, it is not picking the value of the record producer's variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 04:37 AM
is there any read role given in that Permissions tab?
Did you try running script to print that variable value using background script as admin?
Seems your workflow is running in some user's session and it's not having access to this variable
This you can confirm if you run script using admin using background script
Try this and share result
var rec = new GlideRecord('target table of record producer'); // give target table of record producer
if(rec.get('sysId')){ // give record sysId
gs.info(rec.variables.u_approval_to_hire_id);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 05:09 AM
Yes, I've tried that in the Background script. But it also not populating. Below is the output of your script, which is working fine:
*** Script: 345
Let me send you the background script that I used for debugging:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 05:29 AM
you are fetching variable value from RITM record which is not submitted via record producer
what value came here?
gs.info("Approval to Hire ID from Producer: " + approvalToHireId);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2025 05:33 AM
@Ankur Bawiskar it's empty