Add VIP Flag to Opened For on Interaction Records

marrerocmm
Tera Contributor

I'm trying to add a VIP flag (similar to the OOB flag on incident caller) to the "opened for" field on interactions. I'm trying to repurpose the same client script from incident (see below), but am receiving this error "onChange script error: TypeError: $ is not a function function () { [native code] }". Please let me know if there is a better way to go about doing this or any changes you would recommend to my script below, thank you in advance!

 

function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = $('label.interaction.opened_for');
var callerField = $('sys_display.interaction.opened_for');
if (!callerLabel || !callerField)
return;

if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}
g_form.getReference('opened_for', vipCallerCallback);
}

function vipCallerCallback(caller) {
var callerLabel = $('label.interaction.opened_for').down('label');
var callerField = $('sys_display.interaction.opened_for');
if (!callerLabel || !callerField)
return;

//check for VIP status
if (caller.vip == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";

callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}

1 ACCEPTED SOLUTION

Hello marrerocmm,

Try to run this code:

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

    var callerLabel = $('label.interaction.opened_for');
    var callerField = $('sys_display.interaction.opened_for');
    if (!callerLabel || !callerField)
        return;



    g_form.getReference('opened_for', vipCallerCallbackINT);
}

function vipCallerCallbackINT(caller) {

    var callerLabel = $('label.interaction.opened_for').down('label');
    var callerField = $('sys_display.interaction.opened_for');
    if (!callerLabel || !callerField)
        return;

    //check for VIP status
    if (caller.vip == 'true') {
        var bgPosition = "95% 55%";
        if (document.documentElement.getAttribute('data-doctype') == 'true')
            bgPosition = "5% 45%";

        callerLabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: bgPosition,
            paddingLeft: '30px'
        });
        //set callerField color
        callerField.setStyle({
            color: "red"
        });
    } else {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
    }
}

 

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz




View solution in original post

4 REPLIES 4

Filipe Cruz
Kilo Sage
Kilo Sage

Hello,

At least this code will not work:

var callerLabel = $('label.interaction.opened_for');
var callerField = $('sys_display.interaction.opened_for');

Try to replace by:

var callerLabel = g_form.getValue('label.interaction.opened_for');
var callerField = g_form.getValue('sys_display.interaction.opened_for');

 

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

Thanks so much for your response Filipe! The script isn't generating an error anymore, but it isn't showing the VIP flag either. Here is the updated script:

 

function onChange(control, oldValue, newValue, isLoading) {
var callerLabel = g_form.getValue('label.interaction.opened_for');
var callerField = g_form.getValue('sys_display.interaction.opened_for');
if (!callerLabel || !callerField)
return;

if (!newValue) {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
return;
}
g_form.getReference('opened_for', vipCallerCallback);
}

function vipCallerCallback(caller) {
var callerLabel = $('label.interaction.opened_for').down('label');
var callerField = $('sys_display.interaction.opened_for');
if (!callerLabel || !callerField)
return;

//check for VIP status
if (caller.vip == 'true') {
var bgPosition = "95% 55%";
if (document.documentElement.getAttribute('data-doctype') == 'true')
bgPosition = "5% 45%";

callerLabel.setStyle({backgroundImage: "url(images/icons/vip.gif)", backgroundRepeat: "no-repeat", backgroundPosition: bgPosition, paddingLeft: '30px' });
callerField.setStyle({color: "red"});
} else {
callerLabel.setStyle({backgroundImage: ""});
callerField.setStyle({color: ""});
}
}

Hello marrerocmm,

Try to run this code:

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

    var callerLabel = $('label.interaction.opened_for');
    var callerField = $('sys_display.interaction.opened_for');
    if (!callerLabel || !callerField)
        return;



    g_form.getReference('opened_for', vipCallerCallbackINT);
}

function vipCallerCallbackINT(caller) {

    var callerLabel = $('label.interaction.opened_for').down('label');
    var callerField = $('sys_display.interaction.opened_for');
    if (!callerLabel || !callerField)
        return;

    //check for VIP status
    if (caller.vip == 'true') {
        var bgPosition = "95% 55%";
        if (document.documentElement.getAttribute('data-doctype') == 'true')
            bgPosition = "5% 45%";

        callerLabel.setStyle({
            backgroundImage: "url(images/icons/vip.gif)",
            backgroundRepeat: "no-repeat",
            backgroundPosition: bgPosition,
            paddingLeft: '30px'
        });
        //set callerField color
        callerField.setStyle({
            color: "red"
        });
    } else {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
    }
}

 

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz




Thank you Filipe! That worked! I did have to add the "isolate script" checkbox to the client script form and uncheck it, but once I did that the script worked. Thank you very much for your help!