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

Hi,

did you try to get data from some other field?

If that doesn't work then you can use GlideAjax

Regards
Ankur

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

Yep , I tried another field without any luck . I just tried GlideAjax ,but no luck .  Do you see any errors in my code : 

Server Include : 

find_real_file.png

 

Client Script: 

find_real_file.png

Hi,

you forgot to add this line in Ajax

add this after line 4 to call the function

gaPhone.addParam('sysparm_name', 'get_phone');

Regards
Ankur

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

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

Hi Mike,

 

in script include line no:7. replace project with sysparm_user

this.getParameter("sysparm_user");