The CreatorCon Call for Content is officially open! Get started here.

Client side script and Script include not working

NamitD
Tera Contributor

Hello ,

 

I am trying to set VIP checkbox as true if a user is vip in incident form via client script and script include , here is my code but its not working . I created new field on incident form to set it but its not working and not returning anything via alert as well. Any help ?


Client Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   var c = g_form.getValue('caller_id');

   var g = new GlideAjax('userV');
   g.addParam('sysparm_name','isVip');
   g.addParam('sysparm_value',c);
   g.getXMLAnswer(call);

   function call(response){
    var answer = response.responseXML.documentElement.getAttribute('answer');
    alert(answer);
    g_form.setValue('u_vip',answer);

   //Type appropriate comment here, and begin script below
   
}
 
 
Script Include:

var userV = Class.create();
userV.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    isVip : function(){
        var u = this.getParameter('sysparm_value');
        var sr= new GlideRecord(sys_user);
        sr.addQuery('sys_id',u);
        sr.query();
        if(sr.next()){
            var s = sr.vip;
            return s;
        }
       


},
    type: 'userV'
});




1 ACCEPTED SOLUTION

Hi @NamitD ,

 

I have tried the below in PDI and it is working. Please check the below for reference:

 

Script Include(client callable - true)

SN_Learn_0-1721038545181.png

 

var userV = Class.create();
userV.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    isVip: function() {
        var userID = this.getParameter('sysparm_value');

        var userTab = new GlideRecord('sys_user');
        if (userTab.get(userID)) {
            var checkVIP = userTab.vip;
        }
        return checkVIP;
    },

    type: 'userV'
});

Also, check if there are any ACL created when you are creating script include, like below. You need to evaluate true according to it otherwise it wont work, OR you can disable the ACL after elevating to 'security_admin'.

SN_Learn_1-1721038638942.png

 

 

 

onChange Client Script:

SN_Learn_2-1721038739319.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var c = g_form.getValue('caller_id');

    var g = new GlideAjax('userV');
    g.addParam('sysparm_name', 'isVip');
    g.addParam('sysparm_value', c);
    g.getXML(userVIPCheck);

    function userVIPCheck(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('u_vip', answer);

    }
}

 

 

Output:

 

Not a VIP User:

 

SN_Learn_3-1721038784551.png

 

VIP User:

SN_Learn_4-1721038832562.png

 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

View solution in original post

7 REPLIES 7

NamitD
Tera Contributor

@Its_Azar @SN_Learn I tried these but its not reflecting on the form . Its not showing u_vip as true on the form . 

Hi @NamitD ,

 

I have tried the below in PDI and it is working. Please check the below for reference:

 

Script Include(client callable - true)

SN_Learn_0-1721038545181.png

 

var userV = Class.create();
userV.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    isVip: function() {
        var userID = this.getParameter('sysparm_value');

        var userTab = new GlideRecord('sys_user');
        if (userTab.get(userID)) {
            var checkVIP = userTab.vip;
        }
        return checkVIP;
    },

    type: 'userV'
});

Also, check if there are any ACL created when you are creating script include, like below. You need to evaluate true according to it otherwise it wont work, OR you can disable the ACL after elevating to 'security_admin'.

SN_Learn_1-1721038638942.png

 

 

 

onChange Client Script:

SN_Learn_2-1721038739319.png

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var c = g_form.getValue('caller_id');

    var g = new GlideAjax('userV');
    g.addParam('sysparm_name', 'isVip');
    g.addParam('sysparm_value', c);
    g.getXML(userVIPCheck);

    function userVIPCheck(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        g_form.setValue('u_vip', answer);

    }
}

 

 

Output:

 

Not a VIP User:

 

SN_Learn_3-1721038784551.png

 

VIP User:

SN_Learn_4-1721038832562.png

 

 

Mark this as Helpful / Accept the Solution if this helps

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

NamitD
Tera Contributor

Hi @SN_Learn ,

 

 

yes your solution did worked , I was using getXMLAnswer instead of getXML thats why it wasnt working.

Thanks