Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Bump for help.

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');
        }
    });
}

 

Facing same issue 

Geoffrey_Bishop
Giga Expert

Hello, folks.  Am I doing something wrong, or can COLORED decorations not subsequently be removed with "removeDecoration"???

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	var sDecorationMessage = "To save a Problem record, either 'Service' OR 'Configuration Item' must be filled out.";

	if (! g_form.getValue("cmdb_ci") && !g_form.getValue("business_service")){
		//g_form.addDecoration("cmdb_ci", "icon-star", sDecorationMessage, "color-blue"); //It seems like docorations with COLORS can't later be removed.
		//g_form.addDecoration("business_service", "icon-star", sDecorationMessage, "color-blue");  //Can't later be removed.
		g_form.addDecoration("cmdb_ci", "icon-star", sDecorationMessage); //Works
		g_form.addDecoration("business_service", "icon-star", sDecorationMessage); //Works
	}
	else
	{
		g_form.removeDecoration("cmdb_ci", "icon-star", sDecorationMessage);
		g_form.removeDecoration("business_service", "icon-star", sDecorationMessage);
	}	
}

The color parameter can be used for example the following works for me:

g_form.removeDecoration('caller_id', 'icon-accessibility', 'User Sentiment - Red Unhappy, Amber Neutral, Green Happy. This is calculated from surveys taken over time','color-red');

This undoes

  g_form.addDecoration('u_actual_sent_overall', 'icon-accessibility', 'User Sentiment - Red Unhappy, Amber Neutral, Green Happy. This is calculated from surveys taken over time', 'color-red');

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul