Trying to fetch VIP status of caller using Script Include

Suraj Mahajan
Tera Contributor

Hi I have requirement to set the Description "Caller is VIP" if caller is VIP.

I am new to the platform.

I am not able to find mistakes in my code Can anyone help.

 

Client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    var vr= new GlideAjax('setDescCallerVIP');
    vr.addParam('sysparm_name','getcallerinfo');
    vr.addParam('sysparm_caller',g_form.getValue('caller_id').toString());
    vr.getXML(setdet);
   

    function setdet(response){
        var vipStatus = response.responseXML.documentElement.getAttribute("answer");
        alert(response);
        if(vipStatus==true){
            g_form.setValue('description','This Caller Is VIP');
        }
        else{
            g_form.setValue('description','This Caller Is Not VIP');
        }
    }
      //Type appropriate comment here, and begin script below
}
 
 
Script Include:
var setDescCallerVIP = Class.create();
setDescCallerVIP.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getcallerinfo: function() {

        var clr = this.getParameter('sysparm_user');
        var gr = new GlideRecord('user');
       var vip = gr.getValue('vip');
        return vip.toString();
    },
    type: 'setDescCallerVIP'
});
1 ACCEPTED SOLUTION

Sujatha V M
Kilo Patron
Kilo Patron

@Suraj Mahajan  Please follow the below steps for your requirement, 

 

1. Script Include: 

 

SujathaVM_0-1725346779199.png

 

var setDescCallerVIP = Class.create();
setDescCallerVIP.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getcallerinfo: function() {
        var clr = this.getParameter('sysparm_caller');
        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', clr);
		gr.query();
		while(gr.next()){
			var vipStatus = gr.getValue('vip');
			return vipStatus;
		}		
    },
    type: 'setDescCallerVIP'
});

 

2. Client Script

 

SujathaVM_1-1725346841548.png

 

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

    var vr = new GlideAjax('setDescCallerVIP');
    vr.addParam('sysparm_name', 'getcallerinfo');
    vr.addParam('sysparm_caller', g_form.getValue('caller_id'));
    vr.getXML(setdet);

    function setdet(response) {
        var vipStatus = response.responseXML.documentElement.getAttribute('answer');
        alert(vipStatus);
        if (vipStatus == true) {
			g_form.clearValue('description');
            g_form.setValue('description', 'This Caller Is VIP');
        } else {
			g_form.clearValue('description');
            g_form.setValue('description', 'This Caller Is Not VIP');
        }
    }
   
}

 

Results : 

 

If the caller is not VIP, 

 

SujathaVM_2-1725346912321.png

If the caller is VIP, 

 

SujathaVM_3-1725346944727.png

 

Note: Comment out the alert on the client script. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

View solution in original post

3 REPLIES 3

Sujatha V M
Kilo Patron
Kilo Patron

@Suraj Mahajan  Please follow the below steps for your requirement, 

 

1. Script Include: 

 

SujathaVM_0-1725346779199.png

 

var setDescCallerVIP = Class.create();
setDescCallerVIP.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getcallerinfo: function() {
        var clr = this.getParameter('sysparm_caller');
        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', clr);
		gr.query();
		while(gr.next()){
			var vipStatus = gr.getValue('vip');
			return vipStatus;
		}		
    },
    type: 'setDescCallerVIP'
});

 

2. Client Script

 

SujathaVM_1-1725346841548.png

 

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

    var vr = new GlideAjax('setDescCallerVIP');
    vr.addParam('sysparm_name', 'getcallerinfo');
    vr.addParam('sysparm_caller', g_form.getValue('caller_id'));
    vr.getXML(setdet);

    function setdet(response) {
        var vipStatus = response.responseXML.documentElement.getAttribute('answer');
        alert(vipStatus);
        if (vipStatus == true) {
			g_form.clearValue('description');
            g_form.setValue('description', 'This Caller Is VIP');
        } else {
			g_form.clearValue('description');
            g_form.setValue('description', 'This Caller Is Not VIP');
        }
    }
   
}

 

Results : 

 

If the caller is not VIP, 

 

SujathaVM_2-1725346912321.png

If the caller is VIP, 

 

SujathaVM_3-1725346944727.png

 

Note: Comment out the alert on the client script. 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.

Suraj Mahajan
Tera Contributor

@Sujatha V M Thank you very much

@Suraj Mahajan  Glad to help you on it! Kindly understand the logic and implementation so that you will be able to help others too 🙂

 

Happy Learning! 

 

Please mark this as helpful and accept it as a solution if this resolves your query.
Sujatha V.M.