
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Hi community,
within my team we had a discussion about scripting within Flow Designer. We realized that we created tons of Script Actions for one time scripts. This caused our flow action list to grow immeasurably and makes us doubt that we will be able to manage this in the future. Especially when script actions are no longer needed because the associated flows are no longer used.
We have come up with an approach that I would like to put up for discussion here.
Here's the idea: we store such scripts in Script Includes and call them via a generic script action. What do you think of this and if you don't think it's a bad idea, perhaps you have some suggestions for improving the approach?
Now, step by step, what we have come up with:
Create a Script Action "Run Script"
First define 3 Input Parameters:
- Name of Script Include where the function is placed
- Name of Function within the Script include which should be called
- Array of Strings as Input values for the function
Use Script Step to call the Script Include:
- Ensure that input parameters are available within script by mapping the input variables
- Use inputs variables to build a function call script and utilize the dynamic capabilities to instantiate a Script Include class and call a function (Edit: thanks to @rsander without utilizing evil eval anymore)
(function execute(inputs, outputs) {
var SI_Class = JSUtil.getGlobal()[inputs.script_include];
var result = new SI_Class()[inputs.function_name](inputs.input);
outputs.return_object = result;
})(inputs, outputs);
- Don't forget to define the output variables for the script step - in our case a String Array called return_object
Map the Script Step Output to the Action Output
Create a Script Include to encapsulate your scripts
As our script action allows to define the Script Include name you can use for each usage a new Script Include or you use a central Script Include and adds new functions for each use case. It's your choice.
Here is an example how this SI could look like:
Here is the code of this example Script Include:
var ScriptActionTestSI = Class.create();
ScriptActionTestSI.prototype = {
initialize: function() {
},
test_function : function(input){
var a = input[0];
var b = input[1];
result = [];
result[0] = a+b;
result[1] ="DBOR";
return result;
},
type: 'ScriptActionTestSI'
};
You can create any Script Include and define your own functions, names doesn't matter, as you define them as input in the Run Script action. We have only two restrictions regarding the function signature:
- As the input parameter needs to be generic, we decided to use a Array of Strings. If you need complex objects there, you can use JSON.stringify() and JSON.parse() to transfer these.
- Also the output should be generic, that's why we also have chosen a string array.
But as mentioned, it's not really a restriction because these string could also contain complex objects in JSON format.
Usage of Script Action within flow
As an example the flow simple calls the new action and logs the result afterwards:
The result of this flow:
Conclusion
To summarise, my intention is not to recommend this approach as best practice, but rather to hear your opinion on it. From our point of view, this saves a lot of single use actions, but adds another level of complexity, in which the good old script include now has to be used in addition to the flow and action editor.
So fire away, what's your opinion dear community.
- 4,171 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.