- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hello experts,
I have a hardware catalog item in pc_hardware_catalog_item table. I want that the catalog item should only be available to VIP users. For that i have created a 'Available For' user criteria containing a script but it is not working as expected . Am i doing something wrong. Kindly help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi @Deepika54
Try this script:
answer = checkVIPStatus(user_id);
function checkVIPStatus(userID) {
var userGr = new GlideRecord('sys_user');
if (userGr.get(userID)) {
if (userGr.getValue('vip') == '1' || userGr.getValue('vip') == true) {
return true;
}
}
return false;
}
Note: update as necessary
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hello!
The if statement is where you are having issues. I believe you are trying to use the IF statement to verify if the user_id exists. However, the if statement to achieve that would have to be:
(function() {
var gr = new GlideRecord("sys_user");
if (user_id) {
gr.get(user_id);
}
answer = gr.vip;
})();
This verifies a user_id exists, before applying the getRecord call. However, because this is a user criteria, the user_id will never not exist as all user records have a sys_id and that is what user_id is referencing. So I would recommend the following:
(function() {
var gr = new GlideRecord("sys_user");
gr.get(user_id);
answer = gr.vip;
})();
Hope this Helps!
Please Accept the Solution if I assisted you with your question & Mark this response as Helpful.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Using gr.vip will return an object and not the field value. You may want to use gr.getDisplayValue('vip') instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thursday
Hi @Deepika54
Try this script:
answer = checkVIPStatus(user_id);
function checkVIPStatus(userID) {
var userGr = new GlideRecord('sys_user');
if (userGr.get(userID)) {
if (userGr.getValue('vip') == '1' || userGr.getValue('vip') == true) {
return true;
}
}
return false;
}
Note: update as necessary
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti