VIP icon on Catalog Variables not setting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 07:23 AM
Hi All,
When an itil user is trying to submit a catalog item from the native UI, and a VIP user is been selected on the "requested for" field. The VIP Icon should appear on the "Requested for" variable.
I know a catalog client script need to be created and I did created one, but the icon is not showing when a vip user is been selected from the "requested for" variable.
Below is my catalog client script
I got the code from VIP Icon on Catalog Variable which they confirm is working but mine is not working as expected.
Please assist.
function onLoad() {
//Type appropriate comment here, and begin script below
var user = g_form.getReference('requested_for', callBackMethod);
}
function callBackMethod(user) {
if (user.vip.toString() == 'true') {
var variableQuestionValue = 'requested_for';
$j("<img src='images/icons/vip.gif'>").insertAfter("span.sn-tooltip-basic:contains(" + variableQuestionValue + ")");
}
}
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2024 07:55 AM
The problem is your Catalog Client Script is set to run "onLoad", so it will only run once, when the form is originally rendered for your users. Any change to the "requested_for" Variable will not trigger it.
From the link you provided, that client script was written to run on the Requested Item form once the request was actually submitted and the user would not change. You could change it to an "onChange" script instead and see if it runs, although using jQuery to insert the icon is not the recommended way to do it. And you need to hide the icon if the selected user is NOT a VIP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 03:51 AM
Hi @Ken61 ,
It seems the issue with the timing or the structure, please try the below code once-
function onLoad() {
// Get the reference of the 'requested_for' field and call the callback method
g_form.getReference('requested_for', callBackMethod);
}
function callBackMethod(user) {
if (user.vip == 'true') {
var variableQuestionValue = 'requested_for';
// Use the correct selector to insert the VIP icon after the requested_for variable
$j("<img src='images/icons/vip.gif' style='margin-left: 5px;'>").insertAfter("label[for='IO:" + variableQuestionValue + "']");
}
}
Please try giving a thumbs up if your issue is resolved and accept the solution.
Thanks and Regards,
Sanjay Kumar