- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2019 10:11 AM
Is it best practice to dot walk within an onChange catalog client as seen below:
var company = g_form.getValue('model_manufacturer');
var contact = g_form.getDisplayValue('company_phone');
var gr = new GlideRecord("core_company");
gr.addQuery('sys_id', company);
gr.query();
if (gr.next()) {
g_form.setValue("company_phone", gr.getDisplayValue('phone'));
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2019 10:13 AM
Always use a call back function in client side scripting
https://www.servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Try this:
var company = g_form.getValue('model_manufacturer'); var gr = new GlideRecord('core_company'); gr.addQuery('sys_id', company) gr.query(myCallbackFunction); //Execute the query with callback function //After the server returns the query recordset, continue here function myCallbackFunction(gr){ while (gr.next()) { //While the recordset contains records, iterate through them alert(gr.phone.getDisplayValue()); g_form.setValue("company_phone", gr.phone.getDisplayValue()); } }
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2019 10:13 AM
Always use a call back function in client side scripting
https://www.servicenowguru.com/scripting/client-scripts-scripting/gform-getreference-callback/
Try this:
var company = g_form.getValue('model_manufacturer'); var gr = new GlideRecord('core_company'); gr.addQuery('sys_id', company) gr.query(myCallbackFunction); //Execute the query with callback function //After the server returns the query recordset, continue here function myCallbackFunction(gr){ while (gr.next()) { //While the recordset contains records, iterate through them alert(gr.phone.getDisplayValue()); g_form.setValue("company_phone", gr.phone.getDisplayValue()); } }
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2019 10:18 AM
if the GlideRecord gets the data why resort to ajax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-25-2019 10:56 AM
Ajax is asynchronous and provides a better user experience since it will not bog down the browser waiting for the server to return the information.
For small server queries it really doesn't matter much, but it is a good habit to use the asynchronous method.