Date Posted: 2019-09-23
Product: TIBCO Spotfire®
Product: TIBCO Spotfire®
InvalidOperationException when executing the ExportToPdf() API from IronPython script through Automation Services.
Consider the below IronPython script which performs an Export To Pdf:
# Get the prepared report result = Application.Document.TryGetReport("Weekly Sales report") # Check result if result == True: # Export the PDF report = result exportResult = report.ExportToPdf("c:\\Source\\test.pdf")The above script runs alright when executed from Analyst as well as from Web Player.
Note: It requires that the "Execute in Transaction" option is un checked.
As such all IronPython scripts are executed in transaction, and hence any code that starts a progress or aggregated transaction will fail unless the check box "Execute in Transaction" is unchecked.
However the above script fails with below exception if triggered from Automation Services irrespective of whether the script has the 'Execute in transaction' option unchecked.
System.InvalidOperationException: Invalid operation 'BeginAggregatedTransaction' to the command history when in state 'Executing'. at Spotfire.Dxp.Framework.Commands.CommandHistory.BeginAggregatedTransaction(String displayName, Boolean transient, DocumentNode node) at Spotfire.Dxp.Framework.DocumentModel.DocumentNode.BeginTransientTransaction() at Spotfire.Dxp.Application.Export.PreparedExportReport.PreparedExportReport.BuildResultCache(Nullable`1 maxRepetitions) at Spotfire.Dxp.Web.Export.PreparedExportReportBuilder.BuildForExport(PreparedExportReport preparedExportReport) at Spotfire.Dxp.Web.Export.ReportExporter.Export(Report report, Stream outputStream, String& errorMessage) at Spotfire.Dxp.Application.Export.Report.ExportToPdf(Stream outputStream) at Spotfire.Dxp.Application.Export.Report.ExportToPdf(String fileName) at Microsoft.Scripting.Interpreter.FuncCallInstruction`3.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) at Spotfire.Dxp.Application.IronPython27.IronPythonScriptEngine.ExecuteForDebugging(String scriptCode, Dictionary`2 scope, Stream outputStream)“
This is a limitation to what can be done with IronPython scripts in Spotfire.
A script that is triggered by the change of a document property will always execute in the same transaction as the one that made the change of the property, regardless of whether the script has the 'Execute in transaction' option unchecked. This means export operations may not be made in such scripts.
In case you wish to
1. Load a file from the library
2. Export to PDF
then we suggest that you do this with two separate Automation Services tasks instead of implementing scripts triggered by changes of document properties and configuration blocks. There are Automation Services tasks (Load a file from the library, Export to PDF) designed for this purpose.