Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How do I remove a Decoration via OnChange?

Shane J
Tera Guru

What can I use to remove a decoration added via g_form.addDecoration in an onChange Client Script?  g_form.removeDecoration isn't available.

1 ACCEPTED SOLUTION

So, turns out removeDecoration takes multiple parameters.  I put this on my PDI and tried it out.  I updated the removeDecoration to have three parameters;

g_form.removeDecoration('caller_id', 'icon-star', 'VIP');

 

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

    if (!newValue) {
        callerLabel.setStyle({
            backgroundImage: ""
        });
        callerField.setStyle({
            color: ""
        });
        return;
    }
    g_form.getReference('caller_id', function(caller) {
        var callerLabel = $('label.incident.caller_id').down('label');
        var callerField = $('sys_display.incident.caller_id');
        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: '5px', color: "#e34234" });
            callerLabel.setStyle({
                color: "#e34234"
            });
            callerField.setStyle({
                color: "#e34234"
            });
            g_form.addDecoration('caller_id', 'icon-star', 'VIP');
        } else {
            callerLabel.setStyle({
                backgroundImage: "",
                color: ""
            });
            callerField.setStyle({
                color: ""
            });
            //g_form.removeDecoration('caller_id');
			g_form.removeDecoration('caller_id', 'icon-star', 'VIP');
        }
    });
}

 

View solution in original post

9 REPLIES 9

Jace Benson
Giga Sage

It should be available on both mobile/sp and desktop.  Where is it unavailable?

 

Source: https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

I think you misread.  I changed the VIP Client Script to use addDecoration instead.  The problem is that if the Caller is changed to a non-VIP, the icon doesn't disappear.

 

Can you share your code?  g_form.removeDecoration(...) should be available.

Also so this is on the standard UI or in the service portal?

Maybe I'm just using it incorrectly?

 

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

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

function vipCallerCallback(caller) {
var callerLabel = $('label.incident.caller_id').down('label');
var callerField = $('sys_display.incident.caller_id');
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: '5px', color: "#e34234" });
callerLabel.setStyle({color: "#e34234" });
callerField.setStyle({color: "#e34234"});
g_form.addDecoration('caller_id', 'icon-star', 'VIP');
} else {
callerLabel.setStyle({backgroundImage: "", color: ""});
callerField.setStyle({color: ""});
g_form.removeDecoration('caller_id');
}
}