how can we set vip flag based on users band with out using vip check box on user field

Arun61
Tera Contributor

Hello,

 

we have a requirement to set vip flag on caller field based on users band. on user table we have reference field band if users band is b or b+ then we have to set vip flag on incident caller field

i tried with the below script it is checking for users band and alert test 3 is populating but not setting the flag in incident caller field please help me to fix it.

 

client script

function onLoad() {
    var viuser = g_form.getValue('caller_id');
    //alert("employee"+user);
       
    var fBand = new GlideAjax('global.incidentvipcaller');
    fBand.addParam('sysparm_name', 'incvipBand');
    fBand.addParam('sysparm_val', viuser);
    fBand.getXML(getResponse);
}
 
function getResponse(response) {
    var answer = response.responseXML.documentElement.getAttribute('answer');
    alert('t2');
    if (answer.toLowerCase() == 'B' || answer.toLowerCase() == 'B+' || answer == 'B' || answer == 'B+') {
        alert("test3");
        if (document.documentElement.getAttribute('data-doctype') == 'true')
            alert('t4');
        var callerlabel = $('label.incident.caller_id').down('label');
        var callerfield = $('sys_display.incident.caller_id');
        var bgPosition = "95% 55%";
        bgPosition = "5% 45%";
        callerlabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: bgPosition,
            backgroundSize: "20px",
            paddingLeft: '30px'
        });
        callerfield.setStyle({
            color: "red"
        });
    }
}

script include:_

var incidentvipcaller = Class.create();
incidentvipcaller.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
incvipBand : function(){
        var userId = this.getParameter('sysparm_val');
        var getUserBand = new GlideRecord('sys_user');
        getUserBand.addQuery('sys_id',userId);
        getUserBand.query();
        if(getUserBand.next())
            {
                return getUserBand.u_band.u_approval_level.toString();
            }
    },
    type: 'incidentvipcaller'
});

 

 

 

3 REPLIES 3

Sanjay191
Tera Sage

Hello @Arun61 

1.Please check if you are getting anything in answer please alert that and if you are convert into lower case then put the lower case 'b' instead of 'B' please perfome the required changes and alert the answer.
Please look into this condition     
 
if (answer.toLowerCase() == 'B' || answer.toLowerCase() == 'B+' || answer == 'B' || answer == 'B+'
2. First please check you are  getting the vip check on caller  without the condition to check you css and html works or not then put into the condition and if its not working then modify your code.

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

Thank You



Sanjay191
Tera Sage

Hello @Arun61 
You  also use the Field CSS for this requirement like below that is for the OOB  and you just need to change according to your requirement.

Sanjay191_0-1728635979058.png

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

Thank You




Slava Savitsky
Giga Sage

Why make it so complicated? Why not just set the VIP flag to true based on the value of the band field? What are your reasons for not using the VIP flag? And even if you don't want to use it, all you need to do is configure a field style based on your band field, similar to the one available out of the box.