How to use GlideAjax and Client Scripts with Best Practice in mind
G?ran Lundqvist - ServiceNow Witch Doctor
Expert Training Programs - Principal Delivery Manager | ServiceNow MVP[2017 - 2021] | Author
I've seen a couple of questions in the community about how to get more data from the server when you write a Client Script. What comes in mind is everything from GlideRecord calls, use of getReference method to GlideAjax and g_scratchpad method.
I made a video with having best practice in mind and that would rule out both the GlideRecord call and the getReference. I also show how to avoid another server call when you do a setValue on a reference field which is pretty common to do if your mind might be somewhere else when you write the code.
Here is a link to the video and dont forget to subscribe ;) YouTube Video
And you want an update set with the code that is used in the video, you can find it here:https://github.com/goranlundqvist/Update-sets#glideajax-example?
//G?ran?
Service Delivery Manager & Senior Architect at GlideFast Consulting
4 å¹´Top Tanti looks like you were right, getReference is bad! Definitely something I'll keep in mind in the future.
Expert Training Programs - Principal Delivery Manager | ServiceNow MVP[2017 - 2021] | Author
7 å¹´Updated with a link to an update set with both the client script and Script Include: https://github.com/goranlundqvist/Update-sets#glideajax-example
HCS Application Systems Analyst Senior at UNC Health
7 å¹´As for the reference field issue, use g_form.getDisplayBox('<ref field>').value to return the value and not the sys_id.
ServiceNow Master Architect/Delivery Manager
7 å¹´Robert Bryan getReference is bad :p
All things ServiceNow
7 å¹´Nice keep them coming