Explain each step that needs to be done on script include side to use it for GlideAjax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 10:15 PM
Explain each step that needs to be done on script include side to use it for GlideAjax?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 10:36 PM
Hi @sandeepgujj ,
Let me explain you with one real time example.
Suppose we got a requirement from client stating While creating incident if user select VIP caller, then set the priority critical.
To achieve this you need to do following.
- Create one client script to make Ajax call.
- You need to write script include to write your logic. Make sure script include is client callabl.
Client script code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('UserUtils');
ga.addParam('sysparm_name', 'checkVipUser');
ga.addParam('sysparm_caller_sys_id', newValue);
ga.getXML(ValidateVipUser);
function ValidateVipUser(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer=='true') {
g_form.setValue('priority', 1);
g_form.setValue('urgency', 1);
g_form.setValue('impact', 1);
} else {
g_form.clearValue('priority');
g_form.clearValue('urgency');
g_form.clearValue('impact');
}
}
}
Explanation:
Server Side code:
var UserUtils = Class.create();
UserUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkVipUser: function() {
var caller = this.getParameter('sysparm_caller_sys_id');
var gr = new GlideRecord('sys_user');
gr.get(caller);
return gr.vip;
},
type: 'UserUtils'
});
Explanation:
You can visit this link to understand in deep, like how you can pass multi value from server side to client side.
- https://servicenowwithrunjay.com/glideajax-in-servicenow/
- https://servicenowwithrunjay.com/return-multiple-values-to-glideajax-from-script-include/
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2024 11:14 PM
Hello @sandeepgujj
You can refer this https://www.youtube.com/watch?v=kcKcM50CTyc. to understand each step that needs to be done on script include side to use it for GlideAjax.
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"
Thank You
Juhi Poddar