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

I can't getReference due to system constraints, I need such a way glide ajax

Hi @yardenKrispel try this below code while onChange of caller field to VIP user then the priority will change to 1

client Script: Onchange 

field Name : caller

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {
        return;
    }
    var ga = new GlideAjax('myScriptUtils');
    ga.addParam('sysparm_name', 'checkVipUser');
    ga.addParam('sysparm_caller_sys_id', newValue); //newValue is caller
    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);
        }

Script Include: make sure client callable is true

var myScriptUtils = Class.create();
myScriptUtils.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: 'myScriptUtils'

});

 

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

its work! thank you so much

Jim Coyne
Kilo Patron

The reason it is not working for you based on your original question is because you have the Client Script setup to run "onLoad" instead of "onChange" of the Caller field.  So when the script runs, you more than likely do not actually have a Caller set so your line 6 fails and never attempts to set the Priority field.  When you set a Caller, the script will never run.  So that is your first and most important error.

 

And by the way, as @AnveshKumar M has in his sample script, you should NOT be setting the value of Priority directly, but set the values of Impact and Urgency as they are used to calculate the Priority.

 

You keep saying you can't use getReference "due to system constraints", but that is inaccurate/misleading.  getReference "can" be used, BUT it depends on what your REQUIREMENTS are.  You have 2 different screenshots, one showing the "regular" fulfiller UI and the other looks like from a Workspace.  Where is this Client Script expected to be run from?  And based on that answer, that is where the constraint is coming from.