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

@yardenKrispel / @Sandeep Rajput 

 

Change the client script to this one.

 

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(answer) {
    if (answer == 'true') {
        g_form.setValue("impact", "1");
        g_form.setValue("urgency", "1");
    }
}

 

And, Script Include to the one below.

 

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.getValue('vip') + '';
		}

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

its not work. no change 

yardenKrispel_0-1700492649459.png

 

@yardenKrispel Could you please share the snapshot of your script include. Would like to check if Client callable checkbox on the script include is checked or not.

GlideAjax

yaswanthi2
Giga Sage

Hi @yardenKrispel 

Try below code

function onLoad() {

    var callerID = g_form.getReference('caller_id', VIPtrue);

    function VIPtrue(callerID) {

        if (callerID.vip) {

            g_form.setValue("impact", "1");

            g_form.setValue("urgency", "1");
        }
    }
}