IronPython save file to library error

Hi there,

I am trying to implement an IronPython script found here designed to save a file to a library.

The code looks like this:

# Import namespaces
from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread
from Spotfire.Dxp.Application import DocumentSaveSettings
from Spotfire.Dxp.Framework.Library import *

# Declaring the function which will run async
def saveAsLibraryItem(app, folder, fileName, metaData, saveSettings):
   def f():
      app.SaveAs(folder, fileName, metaData, saveSettings)
   return f

# save local
def saveAsLocal(app, folderName, fileName, saveSettings):
	def f():
		fullPath = folderName + fileName
		app.SaveAs(fullPath, saveSettings)
	return f

# Save as library item
LibraryfolderName = "/GV"
LibraryfileName = "Test"
# Set up the LibraryManager and ensure that we can 
# access the folder path specified
libraryManager = Document.GetService(LibraryManager)
success, libraryFolder = libraryManager.TryGetItem(LibraryfolderName, LibraryItemType.Folder)

# Executing the function on the application thread, and Save the document back to the Library

Application.GetService[ApplicationThread]().InvokeAsynchronously(saveAsLibraryItem(Application, libraryFolder, LibraryfileName, LibraryItemMetadataSettings(), DocumentSaveSettings()))

However, I keep getting the following error:

"TypeError: cannot access protected member GetService without a python subclass of Document"

Any idea how to work around this?

(1) Answer