Catalog Client Script : Doing a query with a sys_id and setting catalog variables to record values

Mike S3
Giga Expert

On load , I am able to get the sys_id that was passed through the URL and I've set this value to a field called project. 

I would like to query the u_earb table to find the record that matches that sys_id . Then populate variables on the catalog based on that record . 

I have a rough script , but it doesn't appear to be working . 

function onLoad() {
 
  var project=	g_form.getValue('project');
	
	var gr = new GlideRecord('u_earb');


gr.addQuery('sys_id',project); 


gr.query();        
 g_form.setValue('u_earb_request_type',gr.u_earb_request_type);

	
}
1 ACCEPTED SOLUTION

update line 5 in client script as this

gaPhone.addParam('sysparm_project', project);

In script include update line 7 as this

this.getParameter("sysparm_project");

regards
Ankur

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

View solution in original post

10 REPLIES 10

Mahesh23
Mega Sage

Hi,

 

Try below code

function onLoad() {
var project = g_form.getValue('project');
	var gr = new GlideRecord('u_earb');
	if(gr.get(project)){
        g_form.setValue('u_earb_request_type',gr.u_earb_request_type);
    }
}

Regards,

Mahesh