Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scripted Breakdown

Gokul Nath
Kilo Sage

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);

 

 

Gokul24_0-1686290794255.png

 

4 REPLIES 4

Priyanka0402
Mega Sage

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

Hello @Priyanka0402 , Thanks for that.

But could you please let me know, how does this fetch VIP enabled users without comparing true false values?

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

jaheerhattiwale
Mega Sage

@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.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023