Server side scripting portal widget snow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 11:46 PM - edited 11-08-2022 11:57 PM
Hello All,
I have the following requirement:
1. Deactivate the user selected from list of records.
2. Also, delete all the relationship that the user has
3. Condition -> current logged in User should not deactivate him/herself
I am trying to do it via Server side scripting but for some reason I do not get it right, need help on the same
data.user = gs.getUserID();
if(input&&input.username)
{
var grUserdel = new GlideRecord('sys_user');
grUserdel.addQuery('sys_id',input.username);
grUserdel.query();
if(grUserdel.next())
{
if(data.user == input.username)
{
gs.addInfoMessage("Logged in User cannot deactivate themselves");
return false;
}
else
{
var userid =grUserdel.sys_id;
grUserdel.active="false";
gs.addInfoMessage("User " +grUserdel.name +" has been Deactivated");
var grUserrel1 = new GlideRecord('cmdb_rel_person');
grUserrel1.addQuery('user',userid);
grUserrel1.query();
while(grUserrel1.next())
{
grUserrel1.deleteMultiple();
}
}
grUserdel.update();
}
}
Experts please need your suggestion here
@Ankur Bawiskar @Saurav9 @Amit Gujarathi @Mark Roethof @AnubhavRitolia @Pavankumar_1 @Murthy Ch @asifnoor @Anurag Tripathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 01:16 AM
Hey Anubhav,
I get this from the console log after stringify
{userid: '6816f79cc0a8016401c5a33be04be441,6816f79cc0a8016401c5a33be04be441',
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 01:26 AM
Hi @DB1
{userid: '6816f79cc0a8016401c5a33be04be441,6816f79cc0a8016401c5a33be04be441'}
Is this your value of input.username?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2022 01:11 AM - edited 11-09-2022 01:12 AM
First of all, it's confusing that the input is input.username and you are querying by sys_id. If the input is really the username, you should use grUserdel.get('user_name', input.username);
Also i would put the check if the current user is same as the input before the GlideRecord query.
