- 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 07:13 PM
I appreciate you attacking my post and trying to clarify things. It wouldn't confuse other users if the answer is not marked as correct, which it's not. Secondly, if the syntax and all that is good, then why is the user getting the error? You provided no solution at all and instead went after mine. Half of which is cut-corner techniques that really shouldn't be done...in my opinion...
In an effort to try and help...and without me looking and doing it all myself, I provided some would-be solutions. Notice those were after my gliderecord and other suggestions, but I digress..
Thanks for mentioning the ability to not use brackets...or leaving spaces in your semi-colons wouldn't affect anything. I didn't know that...and wouldn't do that anyway. Bad habit and messy.
Anyways in background script I did:
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id, 'sys_id');
gr.query;
var random = user.source;
gs.print(random);
Also did different queries with user_name, etc...using my own information
Which resulted in:
Attempted script access to inaccessible member denied - com.glide.sys.User:getSource:()Ljava/lang/String;
Evaluator: java.lang.SecurityException: Illegal access to getter method getSource in class com.glide.sys.User
So perhaps you can't get the source in this manner as you want.
Meaning you probably already could see the error in your syslog.list? Possibly.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 08:32 PM
Going after your post or attacking your post was not my intention. Some part of your answers seemed wrong to me, and I clarified it. Its that simple. If you think my clarification is wrong you are welome to provide your reply.
I encouraged the Author of this thread to put log statements in the business rule, so thats the process of debugging to arrive at a solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2018 05:56 PM
Hi,
Just wanted to check in with your post to see how things are going.
Please see my response above from my testing what I saw.
If I've assisted with arriving at a solution, please mark my post as Helpful/Correct. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2018 08:31 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2024 05:38 PM
In my case I'm using two different tables . does g_scratchpad work for two different tables ?
case:
In incident table there is a field that reference problem table i.e. of name "problem_id" by using display BR and scratchpad i need to move that specific incident number to the respective problem table and set that to a newly created field named "u_incident_ref".
In system logs it was logging data perfectly but while trying to fetch from problem table client script it was showing as undefined
please refer below screenshots for better understanding!