This is part 5 in the series about creating Workbook plugins for Profitbase InVision.
Part 1 : The Basics
Part 2 : Reading data using the Sql Script Web Service API
Part 3 : Writing data using the Sql Script Web Service API
Part 4 : Publishing events to the Workbook
Part 5 : Conditional execution of GenericAction (this one)
Download : Source code and sample database
In this post, we’ll walk through how to configure what to do when the GenericAction of a plugin is called.
Conditional execution of GenericAction in a plugin
A plugin only has one action, the GenericAction. Unless the plugin should do the exact same thing every time it’s called, you need some way of configuring that. For example, in the GenericAction you may need to update the data displayed by a plugin based on the selected value of one or more filters, a Workbook variable or some other thing.
In order to do this, you need to add an instruction the GenericAction call of the component and specify a JSON configuration object that you can use inside your plugin to determine what do do.
The configuration of the GenericAction looks like this
As you can see, I’m calling a method called Configure and passing along a JSON object with a messageCode property. In the onGenericAction method of the plugin, that JSON object is available through the eventData parameter. I can then examine the messageCode and determine what to do, which in this case is to load the possible incident types and causes.
protected onGenericAction(eventData: { messageCode: string }): ng.IPromise<number> { var deferred = this.applicationContext.$q.defer(); if (eventData && eventData.messageCode === 'LOAD') { this.applicationContext.$q.all([ this.loadIncidentTypes(), this.loadIncidentCauses() ]).finally(() => { deferred.resolve(1); }); } else { deferred.resolve(1); } return deferred.promise; }
The Configure method is a built-in feature in InVision, intended to be used for configuring what to do when the GenericAction of a plugin is called.
In this demo I’m hard coding a value as the message code, but it could just as easily have been a Workbook variable or the value of a selected filter, for example
Configure({ "messageCode" : SomeVariable, "starshipId" : Filter("Filters", "Starships").SelectedValue?.Id });
Happy plugin coding!
– The InVision Team