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

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

Thanks a lot Musab, 

although I'd like to know what to add if I'd like to delete the preferences with Users.

So that those without users stay.

Sorry for the typo in my actual post 🙂 

 

Regards,

Kosta

Alright found it actually. 

I simply use:

er.addNotNullQuery('user'); 

 

Hi,

I need something like this, but the user preference I want to delete always pulls a sys_id at the end of it. Is there a way to say "starts with" and still use this script? Specifically, it is the workspace.list.columnWidths property that is giving us a problem. (The issue will be fixed in Utah, but for now, we need to delete it from user's preferences. I'd like to delete them once a day for any new ones that popped up.)
Thanks!