Adding/Removing Icons near Service Catalog Variables

Isac Newton Gab
Tera Contributor

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! 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Isac Newton Gab 

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?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.