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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

use GlideRecord with callback

function onLoad() {

	var project = g_form.getValue('project');
	var gr = new GlideRecord('u_earb');
	gr.addQuery('sys_id',project); 
	gr.query(callBackMethod);
	function callBackMethod(gr){
		g_form.setValue('u_earb_request_type',gr.u_earb_request_type);
	}

}

Regards
Ankur

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

Thanks Ankur , but it looks like its returning an undefined value . I added an alert for gr.u_earb_request_type to see what value was being populated. 

 

find_real_file.png

Hi,

are you using correct field to fetch the data from your table?

Regards
Ankur

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

The sys_id in the project field , does match an actual record in the u_earb table . 

u_earb_request_type is also a valid field in the u_earb table : 

find_real_file.png