This is extension to the article of Creating Custom Functions in Spark UI Toolkit. It don't have option to explain how to define the function with real input parameter and invoke it with data. To understand how to Create Custom Function in Spark, please refer this link.
Here I'll explain how to define the function with real input parameter (not the control input) and how to invoke it with the data.
It's the normal way of writing any parameterized function in custom HTML (Advanced control) in IBM BPM, like openLink(control, val) {//code here;}. Screenshot below.
In this you can see I'm using val variable to get the input and deciding the link to open based on it's value. The suggested way to call the function in spark on any control event is like @openLink() as shown below.

But this will not pass any value. Interestingly as per the explanation in the Spack help, it pass the control reference in the function. and you can't try the combinations of passing the extra value into the function using this approach. I tried following two ways, but both are failure.'

To call the above function and to pass the value in it, you need to use the trick of Control Adressing to address the function and then invoke the function.
Following is the way I can call the function on the Click event of the Spark Button control.
[var f1 = bpmext.ui.getFunctionContext("openLink"); f1.fn(me,1)]
in this getFunctionContext will give the context of the function and then the .fn() is the way to invoke any function.
As suggested by Eric Ducos in comments below, we can use the old school style to call function with parameters :)
Hope this is helpful. If you have any queries or any comments feel free to post as comment to this.
Cheers, Saroj
Here I'll explain how to define the function with real input parameter (not the control input) and how to invoke it with the data.
It's the normal way of writing any parameterized function in custom HTML (Advanced control) in IBM BPM, like openLink(control, val) {//code here;}. Screenshot below.
In this you can see I'm using val variable to get the input and deciding the link to open based on it's value. The suggested way to call the function in spark on any control event is like @openLink() as shown below.
But this will not pass any value. Interestingly as per the explanation in the Spack help, it pass the control reference in the function. and you can't try the combinations of passing the extra value into the function using this approach. I tried following two ways, but both are failure.'
To call the above function and to pass the value in it, you need to use the trick of Control Adressing to address the function and then invoke the function.
Following is the way I can call the function on the Click event of the Spark Button control.
[var f1 = bpmext.ui.getFunctionContext("openLink"); f1.fn(me,1)]
in this getFunctionContext will give the context of the function and then the .fn() is the way to invoke any function.
As suggested by Eric Ducos in comments below, we can use the old school style to call function with parameters :)
Hope this is helpful. If you have any queries or any comments feel free to post as comment to this.
Cheers, Saroj
Hi Saroj,
ReplyDeleteAs mentioned in this dW thread:
...your approach definitely works, but can be made much simpler. Replacing all of your inline logic:
var f1 = bpmext.ui.getFunctionContext("openLink"); f1.fn(me, 1)
with
openLink(me, 1)
...will work just as well, is much simpler, and has a lower execution cost at runtime.
SPARK is meant to be extremely simple. Mechanisms such as bpmext.ui.getFunctionContext(), me.ui.invoke(), and the @fn notation address a much narrower set of use cases that UI developers generally don't have to deal.
In general, if something you're doing in SPARK to looks complex, you're probably working too hard and there's a simpler way to do it :)