Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Copying bookmarks to another user's profile

alliej428
Kilo Contributor

Hi-

Is there a way to copy over bookmarks from one user's profile to another?   I've looked but haven't found a way to do so, and I'm not sure if this is possible.

Thanks!

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

Option 1: Copy them manually by going to sys_ui_bookmark.list, filter for the user and bookmarks you want, open each, replace the user name, right click the form header and select "Insert".



Option 2: Write a script to filter and copy them. This is a bit more involved and a knowledge of JavaScript and the GlideRecord API.



GlideRecord - ServiceNow Wiki


View solution in original post

15 REPLIES 15

aswinsiddaling2
Mega Guru

On what condition do you want a user's bookmarks to some other user and to which user is should be copied?



Thanks and Regards,


Aswin Siddalingam


We have different groups of support members that we're looking to have a default set of bookmarks, and I'm trying to see if what we're after is possible.


Peter de Bock1
Mega Guru

Hi there,

 

I had exactly the same requirement at my customer. So I have created a Fix Script which copies and/or updates Bookmarks from an User to a set of Users. I attached the Fix Script.

If you like it 🙂  please mark my response as helpful

regards, Peter

// Cloning Favorites (Bookmarks) of an User
// Note: Existing bookmarks will be updated based upon the Bookmark title

// Input
var UserFrom= "df2acc0fdb10470056d57e400f96191d"; // Set the sys_id of the User to clone the Bookmarks from
var UsersTo= ["c997c007db10470056d57e400f961919","5f2acc0fdb10470056d57e400f96193c","0ce92383dbad0380e823bc2ffe961987"]; // Set the sys_id's of the Users to clone the Bookmarks to

var gr = new GlideRecord('sys_user');
if (gr.get(UserFrom)) {
	var grBook = new GlideRecord('sys_ui_bookmark');
	grBook.addEncodedQuery('user=df2acc0fdb10470056d57e400f96191d');
	grBook.query();
	gs.log('Start cloning bookmarks from ' + gr.name,'Cloning Favorites (Bookmarks)');
	while (grBook.next()){
		var x;
		
		for (x in UsersTo){
			
			
			//Verify upon existence. Update when already exist
			var grBookCheck = new GlideRecord('sys_ui_bookmark');
			grBookCheck.addEncodedQuery('user='+UsersTo[x]+'^title='+grBook.title);
			grBookCheck.query();
			if (grBookCheck.next()){
				
				grBookCheck.url = grBook.url;
				grBookCheck.order = grBook.order;
				grBookCheck.update();
				gs.log('Bookmark ' +grBook.title + ' updated from ' + gr.name + ' to ' + grBookCheck.user.name,'Cloning Favorites (Bookmarks)');
			} else {
				
				grBook.user = UsersTo[x];
				grBook.insert();
				gs.log('Bookmark ' +grBook.title + ' cloned from ' + gr.name + ' to ' + grBook.user.name,'Cloning Favorites (Bookmarks)');
			}
		}
	}
	gs.log('End cloning bookmarks from ' + gr.name,'Cloning Favorites (Bookmarks)');
	
	
}

 

 

Community Alums
Not applicable

This is a very useful script!  

I would suggest one small change though.  There is a sys_id hard-coded in the encoded query at line 11.  I would suggest changing it to reference the UserFrom variable, so that the script dynamically updates that query.

Before:   grBook.addEncodedQuery('user=df2acc0fdb10470056d57e400f96191d');

After:     grBook.addEncodedQuery('user=' + UserFrom); 

Marcin Kroszel
Kilo Guru

Hi (3y later),

is there any way to copy the image (icon) of each bookmark as well?

grBookCheck.image = grBook.image;

doesn't work.