- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2022 01:34 AM
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 🙂
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2022 03:04 AM
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();
}
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2022 03:04 AM
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();
}
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2022 03:33 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2022 03:41 AM
Alright found it actually.
I simply use:
er.addNotNullQuery('user');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2023 12:38 PM
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!