g_scratchpad underined error

Dwain Bryden
Tera Contributor

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:

find_real_file.png

Onload Client Script:

find_real_file.png

Error:

find_real_file.png

 

 

 

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Any update on this question?  Were you able to resolve the issue?

View solution in original post

14 REPLIES 14

ARG645
Tera Guru

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. 

Jim Coyne
Kilo Patron

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.

find_real_file.png

Note: deleted a previous reply with the exact same text so I could reply to the original poster to avoid any confusion.

Jim Coyne
Kilo Patron

Any update on this question?  Were you able to resolve the issue?

Yes thanks Jim

pawan k singh
Tera Guru

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