how to run ironphython script automatically when dxp file is opened in server or tool.

we have a month dropdown which has months like (jan,feb,..) in order to set that to current month am using Ironpython scripting (datetime) but this script need to run automatically when an user opens the dashboard. for that i have tried using the following script:

Trigger script after data table loads

######################################

import clr

from System.Collections.Generic import List, Dictionary

from Spotfire.Dxp.Data import DataTable

from Spotfire.Dxp.Application.Scripting import ScriptDefinition

from Spotfire.Dxp.Framework.ApplicationModel import NotificationService

 

# Notification service

notify = Application.GetService[NotificationService]()

 

# Get second script

scriptDef = clr.Reference[ScriptDefinition]()

Document.ScriptManager.TryGetScript("yourSecondScriptName", scriptDef)

params = Dictionary[str, object]()

 

# Refresh Callback function

def execCallBack(exception, Document=Document, notify=notify, params=params, scriptDef=scriptDef):

if not exception:

# executes the script

Document.ScriptManager.ExecuteScript(scriptDef.ScriptCode, params)

else:

notify.AddErrorNotification("Error refreshing table(s)","Error details",str(exception))

 

# Get/Add table(s) to refresh

# Note that more than one table can be added to the List object. Repeat the Add() method if needed for multiple tables to refresh.

 

Tbls = List[DataTable]()

Tbls.Add(Document.Data.Tables['yourTableName'])

 

# Refresh table (new 7.0 API)

Document.Data.Tables.RefreshAsync(Tbls, execCallBack)

#############################################

Where 'yourSecondScriptName' and 'yourTableName' are respectively the name of your script and table.

 

note: when i run this script manually, am getting my required output. we cache the data at server 

 

can anyone help me in achieving this. 

Thanks

(5) Answers

Login