Scripted Breakdown
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 11:06 PM
Hi all,
I am trying to create a scripted breakdown to retrieve incidents based on the VIP users. Not sure if I am on the right track. Please help with your suggestions
function getuserstatus(vipstatus) {
var user = new GlideRecord('sys_user');
user.addQuery('vip', vipstatus);
user.query();
if (vipstatus == true) {
userstatus = "VIP User";
} else {
userstatus = "Non-VIP User";
}
return userstatus;
}
getuserstatus(current.caller_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 11:34 PM
Hello @Gokul Nath ,
The original script didn't handle the case when no user was found and it didn't specify the desired columns to retrieve.
Try using the below code:
function getUserStatusByVIP(vipStatus) {
var user = new GlideRecord('sys_user');
user.addQuery('vip', vipStatus);
user.query();
if (user.next()) {
if (vipStatus) {
return "VIP User";
} else {
return "Non-VIP User";
}
} else {
return "No user found";
}
}
getUserStatusByVIP(current.caller_id.vip);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 12:13 AM - edited 06-09-2023 12:15 AM
Hello @Priyanka0402 , Thanks for that.
But could you please let me know, how does this fetch VIP enabled users without comparing true false values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 12:28 AM
Hello @Gokul Nath
This is basic javascript.
if (vipStatus) { // This line will check the Status and will only work if it is true.
return "VIP User";
} else { // This line will work if it is false.
return "Non-VIP User";
}
I hope this helps.
Thanks
Priyanka
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 12:35 AM
@Gokul Nath As you are passing caller_id to the function you need to query on sys id field. Please try below code
function getuserstatus(userSysId) {
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', userSysId);
user.addQuery('vip=true');
user.query();
if(user.hasNext()){
return "VIP User";
}
return "Non-VIP User";
}
getuserstatus(current.caller_id);
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023