Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scratch variable not getting the values to the list variable

ServiceNow Use6
Tera Guru

Hi,

I have created a display business rule and an onLoad client script. It is not working, and the groups are not loading onto the field User Groups (u_user_groups).

 

Display Business Rule

 

 

(function executeRule(current, previous /*null when async*/ ) {
    
	var aq = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', gs.getUserID());
    gr.query();
    while (gr.next()) {

        aq.push(gr.getValue('group'));
    }
    g_scratchpad.sreevani = aq;

})(current, previous);

 

 

onLoad Client Script

 

 

function onLoad() {

	var Suman = g_scratchpad.cloeh;
	if(g_form.isNewRecord()){
	g_form.setValue('u_detailed_description', Suman);
	}
}

 

 

2.jpg

 

3.jpg

 

But when I put in List variable, it is not working.

 

 

function onLoad() {

	var Suman = g_scratchpad.cloeh;
	if(g_form.isNewRecord()){
	g_form.setValue('u_groups', Suman);
	}
}

 

 

6.jpg5.jpg4.jpg

 

Regards

Suman P.

1 ACCEPTED SOLUTION

J Siva
Kilo Patron
Kilo Patron

Hi @ServiceNow Use6 

Your scratchpad variable is storing the group record sys_ids,

But, in the dictionary entry pic, I can see that the reference table is "Employee Stay Request" table. 

Please check that..

Regards,

Siva

View solution in original post

4 REPLIES 4

J Siva
Kilo Patron
Kilo Patron

Hi @ServiceNow Use6 

Your scratchpad variable is storing the group record sys_ids,

But, in the dictionary entry pic, I can see that the reference table is "Employee Stay Request" table. 

Please check that..

Regards,

Siva

ServiceNow Use6
Tera Guru

Hi @J Siva,

Thank you so much. It worked. I am stupid, instead of pointing to the groups table, I pointed out to the table i am working on.

Regards

Suman P.

@ServiceNow Use6 

Sys ID is a unique value across the instance. In your scratchpad variable, you're storing the Sys IDs of group records from the Group table. However, you're attempting to assign these IDs to a field that references the 'Employee Stay Request' table. That's why it didn't work.