I want to delete applications / modules from favourite list in Servicenow

Sachin Gavhane
Giga Guru

I want to delete all the applications and modules in FAVOURITES  via script [ fix script]

SachinGavhane_0-1684756581945.png

I am able to delete only modules , but not able to delete Application named " Incident" via script.

I need it via fix script so that everything [ Application + module ] should get deleted from "favourites".

I am able to delete all the modules via script from bookmarks table but , Currently i am not able to delete application "Incident"

pls note: I want it via script

pls help

@shloke04 

4 REPLIES 4

Amit Gujarathi
Giga Sage
Giga Sage

HI @Sachin Gavhane ,
I trust you are doing great.

  1. First, we need to identify the sys_id of the "Incident" Application. You can do this by searching for the Application in the sys_app table. Look for the record with the name "Incident" and note down its sys_id.

  2. Once you have the sys_id of the "Incident" Application, you can delete the corresponding record from the bookmarks table. The bookmarks table stores the favorite modules and applications for each user.

// Step 1: Get the sys_id of the "Incident" Application
var incidentApp = new GlideRecord('sys_app');
incidentApp.addQuery('name', 'Incident');
incidentApp.query();
if (incidentApp.next()) {
  var incidentAppSysId = incidentApp.sys_id.toString();

  // Step 2: Delete the Application record from the bookmarks table
  var bookmarks = new GlideRecord('sys_bookmark');
  bookmarks.addQuery('module', incidentAppSysId);
  bookmarks.query();
  while (bookmarks.next()) {
    bookmarks.deleteRecord();
  }

  gs.info('Successfully deleted the "Incident" Application from favorites.');
} else {
  gs.info('Unable to find the "Incident" Application.');
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Manmohan K
Tera Sage

Hi @Sachin Gavhane ,

 

You can write a fix script like below and delete favorites

var gr = new GlideRecord('sys_ui_bookmark');
gr.addQuery('user', 'user sys_id');
gr.query();
while (gr.next()) { 
gr.deleteRecord();
}

 

To delete irrespective of user, remove second line and run fix script

BrendanF
Tera Contributor

I think the answer OP was looking for is the sys_ui_bookmark_group table.

Nilesh Wahule
Tera Guru

Hi @Sachin Gavhane ,

 

As @BrendanF@Manmohan K   mentioned, you can perform below query to remove the fav applications as well as modules for a certain user by putting user conditions as below

 

 

var gr = new GlideRecord('sys_ui_bookmark');
gr.addQuery('user', 'user sys_id'); //put user sys_id for which you want to delete fav
gr.query();
gr.deleteMultiple();

var gr = new GlideRecord('sys_ui_bookmark_group');
gr.addQuery('user', 'user sys_id'); //put user sys_id for which you want to delete fav
gr.query();
gr.deleteMultiple();

 

 

Please note that if the records are multiple, its better to put setLimit() condition and if you want to do it for all users , comment down the second line.

 

Please mark my answer as helpful/correct if it resolves your query.

---

Nilesh Wahule