Delete User preferences via Scheduled Script

Konstantinos Di
Mega Guru

Hey there,

I want to delete all User Preferences with a specific name (Lets call it "nameX") and that have no users.

I'm kinda new to service now configuration so I'd appreciate all help 🙂

1 ACCEPTED SOLUTION

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Here is the sample script

var er = new GlideRecord('sys_user_preference');
er.addQuery('name' , 'name of preference');
er.addQuery('user' , '');
er.query();
while(er.next())
{
er.deleteMultiple();
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi,

 

Try this script:

 

var up = new GlideRecord('sys_user_preference');

up.addEncodedQuery('name=xyz^userISEMPTY') //replace name accordingly

up.query();

while(up.next()){

up.deleteMultiple();

}

Karthick9
Tera Contributor

Hi 

 

Please try the below code :


var userPref = new GlideRecord('sys_user_preference');

userPref.addQuery('name','=','nameX');

userPref.addNullQuery('user');

userPref.query();

userPref.setWorkflow(false);

userPref.deleteMultiple();