Jump to content

Notification Service - IronPython script


Priyank Dwivedi
Go to solution Solved by Fredrik Rosell,

Recommended Posts

Hi,

I implemented a notification service code snippet in Ironpython that executes a data function.

The idea is to give a notification to the user that the 'data function was run successfully or not'.

This seems to work if the execution is run with no errors but when the execution fails, the user gets two notifications. First, stating that 'data function ran successfully' and then failure notification.

The issue I suppose is that a 'successful' notification is sent regardless if the user function fails or succeeds or even before the data function was executed completely. How do I handle such scenarios?

from Spotfire.Dxp.Data.DataFunctions import DataFunctionExecutorService, DataFunctionInvocation, DataFunctionInvocationBuilderfrom System.Threading import Threadimport sysfrom Spotfire.Dxp.Framework.ApplicationModel import NotificationService  # Notification servicenotify = Application.GetService[NotificationService]() #Get UserNameDocument.Properties["username"]=Thread.CurrentPrincipal.Identity.Nameprint('hello')  for fnc in Document.Data.DataFunctions: if fnc.Name == 'Save.RawData.v6': try: print('start') fnc.Execute() notify.AddInformationNotification("Well Assignment Process","Data was saved successfully to the database.",""); except:  notify.AddErrorNotification("Well Assignment Process", "Data was not saved successfully to the database.", "");
Link to comment
Share on other sites

  • Solution

Hello,

Maybe you could execute the data function using ExecuteSynchronously and look at the returned result (boolean).

result = fnc.ExecuteSynchronously();

print ('result='+str(result))

if result:

notify.AddInformationNotification("Well Assignment Process","Data was saved successfully to the database.","");

else:

notify.AddErrorNotification("Well Assignment Process", "Data was not saved successfully to the database.", "");

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...