GlideAjax - changes 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 , But this is the only way I need - GlideAjax I am attaching pictures of what I did but it doesn't work 

yardenKrispel_0-1700489727002.png

 

yardenKrispel_1-1700489748631.png

 

12 REPLIES 12

Hi @yardenKrispel ,

 

U commented even the Glide Ajax call. I asked u to comment line 14-20. Can u please share the script here as in copy paste. I will provide u the script u just replace that n check

 

Thanks,

Danish

 

yes this is the script 

 function onLoad() {
    // Get the sys_id of the user associated with the incident
     var userId = g_form.getValue('caller');

    // Make a GlideAjax call to fetch the VIP field from the user record
    getVIPStatus(userId);
 }

 function getVIPStatus(userId) {
     var ga = new GlideAjax('MyGlideAjaxScriptInclude');
     ga.addParam('sysparm_name', 'getVIPStatus');
     ga.addParam('sysparm_sys_id', userId);

    ga.getXMLAnswer(function(response) {
        // Set the priority based on the VIP status
        if (response == 'true') {
            g_form.setValue('priority', '1');

            // Additionally, set urgency, impact, and priority
            g_form.setValue('urgency', '1');
            g_form.setValue('impact', '1');
        }
    });
}

@yardenKrispel ,

 

Please find the updated script

 

 function onLoad() {
    // Get the sys_id of the user associated with the incident
     var userId = g_form.getValue('caller');

    // Make a GlideAjax call to fetch the VIP field from the user record
    getVIPStatus(userId);
 }

 function getVIPStatus(userId) {
     var ga = new GlideAjax('MyGlideAjaxScriptInclude');
     ga.addParam('sysparm_name', 'getVIPStatus');
     ga.addParam('sysparm_sys_id', userId);
ga.getXMLAnswer(_handleResponse);

function _handleResponse(answer) {
	alert(answer);
        if (answer == 'true') {
            // Additionally, set urgency, impact, and priority
            g_form.setValue('urgency', '1');
            g_form.setValue('impact', '1');
g_form.setValue('priority', '1');
        }
    }
}

 

Please try this Also change the "Impact" & "Urgency" field name to proper backend names from incident table

 

Thanks,

Danish

 

yes i try this and is sstill dont work, mabay script includede? this is my code :

var MyGlideAjaxScriptInclude = Class.create();

MyGlideAjaxScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getVIPStatus: function() {
        var userId = this.getParameter('sysparm_user_id');
        var userRecord = new GlideRecord('sys_user');

        if (userRecord.get(userId)) {
            return userRecord.getValue('vip') + '';
        }

        return 'false';
    },

    type: 'MyGlideAjaxScriptInclude'
});

no change 

yardenKrispel_0-1700492365319.png