How to check if logged in user is in the Incident watchlist in Widget server side script?

Aki
Kilo Explorer

Hi All,

We have a 'Incident cancellation' widget which we need to hide if Logged in user is in the Incident watchlist. Please suggest the code snippet for the same.

Thanks

Aki

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi,

On server side script, you would need to check if logged in user is in watch list or not.

If you have incident gliderecord object on server then use below,

var watchListUsers=glideRecordObject.watch_list;

if(watchListUsers.indexOf(gs.getUserID()) > -1){

data.userExist=true;

}else{

data.userExist=false;

}

 

On HTML section of the widget, in the first tag, you would need to include below condition.

 

<div ng-if="!data.userExist">

</div>

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this

var watchListArr = ['userA','userB']; // this will hold the sysId of the users

if(watchListArr.indexOf(gs.getUserID()) > -1){

// present

}

Regards
Ankur

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

Abhijit4
Mega Sage

Hi,

On server side script, you would need to check if logged in user is in watch list or not.

If you have incident gliderecord object on server then use below,

var watchListUsers=glideRecordObject.watch_list;

if(watchListUsers.indexOf(gs.getUserID()) > -1){

data.userExist=true;

}else{

data.userExist=false;

}

 

On HTML section of the widget, in the first tag, you would need to include below condition.

 

<div ng-if="!data.userExist">

</div>

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Thanks, Abhijit.