Adding/Removing Icons near Service Catalog Variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 07:09 AM
Hello All,
I want to add/remove VIP icon in a 'requested for' catalog variable based on the value selected, I was able to find this article below to add icon, VIP Icon on Catalog Variable - ServiceNow Community.
But it is written for On Load of the form, I want it to be written On Change of a 'requested for' variable.
Also, please advise whether this method is DOM manipulation or not? And is this the only method for achieving this?
@Ankur Bawiskar tagging you as it was your blog.
Thanks In Advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 08:25 AM
the blog uses DOM manipulation which is not recommended.
The same logic you can handle in onChange client script based on value selected in another variable
what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 09:09 AM
Thanks for the prompt response.
I have written the below script,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = g_form.getReference('requested_for', callBackMethod);
}
function callBackMethod(user) {
var variableQuestionValue = "Requested For";
if (user.vip.toString() == 'true') {
$j("<img src='images/icons/vip.gif' id = 'id123456'>").insertAfter("span.sn-tooltip-basic:contains(" + variableQuestionValue + ")");
} else {
alert("remove");
$j("#id123456").remove();
}
}
//Type appropriate comment here, and begin script below
The else condition is not working. I am not able to remove the image once added.