How to Copy Favorites/Bookmarks to a Different User

MrDevanWright
Kilo Guru

How can I copy, not move, favorites/bookmarks from one user to another?

 

Exporting an XML, altering the user, then importing an XML from the 'sys_ui_bookmark' list successfully loads the favorites/bookmarks for the new user. However, it also removes them from the old users account.

2 REPLIES 2

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

The export you are describing will contain exactly the same sys_id. Therefor, while changing the user, it will actually move the bookmark... since it's the same sys_id.

 

If you want to copy it, you can do so manually with insert and stay if its a one of. Should this be for a ton of users or frequently, you can create a script. Or... even no code using Flow Designer.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Filip Vojt__ek
Mega Guru

Hi, 

I would say run the background script (don't forget to check 'record for rollback' if anything goes wrong) and just run the script (you need to replace the sys_ids of users):

copyFavourites('3eb28d4ddbf4f0104af9a2bc0XXXXXXX', '4d040b53872fd2d034e864a80XXXXXXX');

function copyFavourites(sourceUserID, targetUserID) {

	var favouritesGR = new GlideRecord('sys_ui_bookmark');
	favouritesGR.addEncodedQuery('user=' + sourceUserID);
	favouritesGR.query();

	while (favouritesGR.next()) {
		favouritesGR.setValue('user', targetUserID);
		favouritesGR.insert();
	}
}