Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

priority

yardenKrispel
Tera Contributor

Hi, I would like to know why the code doesn't work for me? What I need to do is as soon as I open an incident and put in the caller a client who is a VIP, then the priority automatically changes to 1. This is important as soon as I open before I save

 

yardenKrispel_0-1700482654309.png

 

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

@yardenKrispel 

 

Try this updated script, I tested this in my PDI, it is working fine.

 

Client Callable Script Include:

 

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

    checkVIPFlag: function() {
        var caller = this.getParameter("sysparm_caller");
        var usrGr = new GlideRecord('sys_user');
        if (usrGr.get("sys_id", caller)) {
            return usrGr.getValue('vip') + '';
        }

        return '0';
    },
    type: 'CustomUserUtils'
});

 

 

AnveshKumarM_0-1700496681956.png

 

 

Client Script:

AnveshKumarM_1-1700496698262.png

 

 

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

    var caller = g_form.getValue('caller_id');
    var uGa = new GlideAjax('CustomUserUtils');
    uGa.addParam('sysparm_name', 'checkVIPFlag');
    uGa.addParam('sysparm_caller', caller);
    uGa.getXMLAnswer(setPriority);
}

function setPriority(answer) {
    if (answer == '1') {
        g_form.setValue("impact", "1");
        g_form.setValue("urgency", "1");
    }

}

 

 

Result:

AnveshKumarM_0-1700496293819.png

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

 

Thanks,
Anvesh

View solution in original post

14 REPLIES 14

AnveshKumar M
Tera Sage
Tera Sage

Hi @yardenKrispel 

 

For getReference, you need to use callback function, as it goes back to Server and gets the data.

 

Try the below script. 

 

 

 

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

    var caller = g_form.getReference('caller_id', popVIPPriority);

    function popVIPPriority(caller) {
        if (caller.vip == 'true') {
            g_form.setValue("impact", "1");
            g_form.setValue("urgency", "1");
        }
    }

}

 

 

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Anvesh

I can't in getReference due to system constraints, do you have another way of code to give me?

@yardenKrispel Here is the code you should use if you do not wish to use getReference.

 

1. Script Include:Create a client callable script include as follows.

 

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

    getVIPStatus: function() {
        var user_sys_id = this.getParameter("sysparm_user_sys_id");
        var grUser = new GlideRecord('sys_user');		
		var vipStatus='';
        if(grUser.get("sys_id", user_sys_id)){
			vipStatus = grUser.getDisplayValue('vip');
		}

		return vipStatus;
        
    },
    type: 'GetUserInfo'
});

 

Client Script:

 

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

    var caller = g_form.getValue('caller_id');
    var ga = new GlideAjax('GetUserInfo'); // GetUserInfo is the script include name 
    ga.addParam('sysparm_name', 'getVIPStatus'); // getVIPStatus is the function in the script include that we're calling 
    ga.addParam('sysparm_user_sys_id', caller); // set user to Fred Luddy 

    /* Call GetUserInfo.managerName() with user set to Fred Luddy and use the callback function ManagerParse() to return the result when ready */
    ga.getXMLAnswer(setVIPPriority);
}

// callback function for returning the result from the script include
function setVIPPriority(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer == 'true') {
        g_form.setValue("impact", "1");
        g_form.setValue("urgency", "1");
    }
}

 

Hope this helps.

 

 

its not working the prioirty is not change 

yardenKrispel_0-1700490392614.png