Client script with getReference() and callback function doesn't work on Agent Workspace?

gkbhandare003
Kilo Guru

Hi All,

I am writing OnChange Client Script to populate field from cmdb_ci table on incident form in custom field using getReference and Callback method.. This works fine on the Platform UI but doesn't show up any value of Agent Workspace.

Code:

var solution_provider;
	var ref2=g_form.getReference('cmdb_ci',callBack2);
	function callBack2(ref2){
		var asset2 = ref2.support_group;
		var grp = new GlideRecord('sys_user_group');
		grp.addQuery('sys_id', asset2);
		grp.query();
		if (grp.next()) {
			solution_provider = grp.name;
		}
    g_form.setValue('u_solution_provider', solution_provider);
	}

Could there be problem of GlideRecord statement or something like that? I have other scripts which do not need GlideRecord call and they works fine for both platform UI and Agent workspace..

Any suggestions ?

Thanks in advance

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi,

Don't use GlideRecord in client side.

Why not use GlideAjax?

OR

try to use GlideRecord with callback and check once

var solution_provider;
var ref2 = g_form.getReference('cmdb_ci',callBack2);
function callBack2(ref2){
	var asset2 = ref2.support_group;
	var grp = new GlideRecord('sys_user_group');
	grp.addQuery('sys_id', asset2);
	grp.query(checkRecord);

	function checkRecord(grp){
		if(grp.next()){
			var solution_provider = grp.name;
			g_form.setValue('u_solution_provider', solution_provider);
		}
	}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron

Hi,

Don't use GlideRecord in client side.

Why not use GlideAjax?

OR

try to use GlideRecord with callback and check once

var solution_provider;
var ref2 = g_form.getReference('cmdb_ci',callBack2);
function callBack2(ref2){
	var asset2 = ref2.support_group;
	var grp = new GlideRecord('sys_user_group');
	grp.addQuery('sys_id', asset2);
	grp.query(checkRecord);

	function checkRecord(grp){
		if(grp.next()){
			var solution_provider = grp.name;
			g_form.setValue('u_solution_provider', solution_provider);
		}
	}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader