Jump to content
  • How to embed data and save a dashboard locally or on server using automation service in Spotfire® Using IronPython Scripting


    This example shows how to embed data and save a dashboard locally or on server using automation service in Spotfire using IronPython script.

    Introduction

    Using automation services you can embed data and save dashboards only to library. There is no in-built option to embed data and save dashboard locally or on server.

    This example illustrates how this can be done using IronPython script. When you open a dashboard this script will embed the data tables and save the file to the location you mention in the script.

    Code Sample

    # Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    # Import namespaces
    from Spotfire.Dxp.Framework.ApplicationModel import ApplicationThread
    from Spotfire.Dxp.Application import DocumentSaveSettings
    from Spotfire.Dxp.Framework.Library import *
    from Spotfire.Dxp.Data import DataTableSaveSettings
    import datetime
    from System.IO import File, Path
    
    for table in Document.Data.Tables:
       settings = DataTableSaveSettings (table,False, True);
       Document.Data.SaveSettings.DataTableSettings.Add(settings);
    
    
    # save local
    def saveAsLocal(app, folderName, fileName, saveSettings):
        def f():
            fullPath = folderName + fileName
            app.SaveAs(fullPath, saveSettings)
        return f
    
    # Set the folder path and file name for a local file
    folderName = "C:\\"
    fileName = "Test File "
    
    # Save as local file
    Application.GetService[ApplicationThread]().InvokeAsynchronously(saveAsLocal(Application, folderName, fileName, DocumentSaveSettings()))
     

    This script runs each time you run the automation service job and the saved file gets overridden. But if you do not want the file to be overridden then you can save the file with timestamp in its name  For this the parameter 'fileName' should be as below

     fileName = "Test File " +  str(datetime.datetime.now()).replace (":", ".") + ".dxp"
     

    Steps

    1. Open a dashboard
       
    2. Go to Edit->Document properties-> 'Scripts' tab
       
    3. Under 'IronPython' tab select New and add the above script (In script you need to change folderName = "C:\\" to your desired location and in fileName = "Test File " instead of "Test File" give your desired file name)
       
    4. Now go to Properties tab and create a new Property say "Trigger"
       
    5. Select 'Script' button on the right and select Execute the script selected below option and choose the IronPython script created above
       
    6. Now in the Automation Service Job Builder select "Open Analysis from Library" job , in configuration block set the document property created in the previous step to any value different than the current value saved. This will trigger the IronPython script to execute upon opening of the analysis using Automation services.  For example:
     Trigger="Value1";
     

    References

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...