Explain each step that needs to be done on script include side to use it for GlideAjax?

sandeepgujj
Tera Contributor

Explain each step that needs to be done on script include side to use it for GlideAjax?

2 REPLIES 2

Runjay Patel
Giga Sage

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.

  1. Create one client script to make Ajax call.
  2. 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:

RunjayPatel_0-1732602772727.png

 

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:

RunjayPatel_1-1732602818879.png

 

You can visit this link to understand in deep, like how you can pass multi value from server side to client side.

  1. https://servicenowwithrunjay.com/glideajax-in-servicenow/
  2. 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

-------------------------------------------------------------------------

 

 

In this video i have explained about Web service integration in ServiceNow like how it works, how we can configure it, what are the prerequisite and many more. I have covered below topics in this video. 1. understand Web Service. Like when and how we will use it. 2. Talked about Inbound and ...

Juhi Poddar
Kilo Patron

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