Updating bookmarks using bookmark update API and python script does not work

Updating bookmarks using bookmark update API and python script does not work

book

Article ID: KB0071719

calendar_today

Updated On:

Products Versions
Spotfire Service for Python All versions

Description

This article explains how to update bookmarks using Bookarmark Update API via IronPython scripts.

Updating the bookmarks using Bookmark API can be easily achieved using iron python scripts. An instance for the service name BookmarkManager can be created and its internal method Update() can be called for updating the bookmarks.

Below is the sample code -
def save_bookmark( book_mark, name ):
	bookmark_manager = Application.GetService(BookmarkManager)
	if book_mark is None:
		book_mark = bookmark_manager.AddNew( name, BookmarkComponentFlags.All )
		bookmark_manager.SetPublicVisibility( book_mark, True )
	else:
		bookmark_manager.Update(book_mark)
		bookmark_manager.SetPublicVisibility( book_mark, True )

Issue/Introduction

BookmarkManager.Update() API is not working while adding or modifying the bookmarks.

Resolution

The above code illustrates- while marking row/rows to be bookmarked by the desired bookmark name if the name is not present in the bookmark directory the new bookmark will be created and if the entered bookmark name is already present then it should update it with the new values/rows. The above example code will compile and run successfully without any warning or errors, but it will not give the expected result that is it will not update the bookmarks.

The reason it is not updating is as when the update method is called, then its current state is updated, and its current state should be used in the call SetPublicVisibility()

Below is the example which would help to update the bookmarks correctly via Update API.
def save_bookmark( book_mark, name ):
	bookmark_manager = Application.GetService(BookmarkManager)
	if book_mark is None:
		book_mark = bookmark_manager.AddNew( name, BookmarkComponentFlags.All )
		bookmark_manager.SetPublicVisibility( book_mark, True )
	else:
		updatedBookmark = bookmark_manager.Update(book_mark)
		bookmark_manager.SetPublicVisibility( updatedBookmark, True )

The above example stores its current state in a local variable and then the local variable is passed to the SetPublicVisibility method to set its current state. This helps to update the Bookmark in the correct manner.
 

Additional Information

Doc: API Reference:Bookmanager-Update: