- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 05:54 PM
Hi Guys,
I have a display business rule that I am calling from a client script. When calling using g_scratchpad I am getting a "undefined" error when trying to retrieve the value of the field.
I know i am missing something really small please see below:
Display Business Rule:
Onload Client Script:
Error:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2018 11:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 06:28 PM
Your code is all good and straight forward. All the syntax is good.
Put a log statement using gs.log(user.getValue('source')); in your business rule and see what its resulting in.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 08:42 PM
Your Business Rule script seems to be OK, but you might want to try something like this with a check to make sure the record was returned:
(function executeRule(current, previous /*null when async*/) {
//initialize the return value
var source = "";
//get the User record
var gr = new GlideRecord("sys_user");
if (gr.get(gs.getUserID())){
//grab the contents of the Source field, if the record is found (should always)
source = gr.getValue("source");
}
g_scratchpad.u_source = source;
})(current, previous);
I would prefix the scratchpad variable with a "u_" to avoid issues in the future where ServiceNow "could" possibly add their own data to g_scratchpad.source.
The only thing I can think of is the BR is not really setup as a Display BR. Or not active? Can you include a screenshot of the "When to run" tab of the BR record?
Also, you might find this tool helpful when using the g_scratchpad object - "Show Contents of g_scratchpad" Tool.
Note: deleted a previous reply with the exact same text so I could reply to the original poster to avoid any confusion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2018 11:18 AM
Any update on this question? Were you able to resolve the issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-24-2018 05:11 AM
Yes thanks Jim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2021 02:46 AM
Had similar issue, in my case it was happened due to Display Business rule was written on the different table and we were using g_scratchpad in different table.
So after adding same Display Business rule for the table used in Client script resolved our issue.
Regards
Pawan K Singh