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.

Server side scripting portal widget snow

DB1
Tera Contributor

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 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@DB1 

So what's not working? where are you facing challenge?

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

DB1
Tera Contributor

Thanks for the reply, I do not see the Info message appearing and validating on Portal

@DB1 

what debugging have you performed so far?

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

AnubhavRitolia
Mega Sage

Hi @DB1 

 

What value are you passing in 'input.username' value. Can you add log for it and tell what you are getting in this variable value?

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023