Shared Scriptlets On A Flow

Is it possible to use a shared scriptlet on a flow?

I have a scriptlet stored in the Configuration\Scriptlets folder and I want to use this on a flow (via Properties > Scriptlet). I drag this on to the scriptlet text pane and Studio tells me it now has a reference to a Shared Scriptlet and I have the button to allow me to switch back to a custom scriptlet as expected.

When I execute this flow it seems the scriptlet is never executed, I've even tested with a temp scriptlet which just places a variable in to the flow context and it never appears.


  • Hi,

    When adding a variable to the context via scriptlet make sure to use scriptletContext.put("LocalVariable","LocalValue");  instead of scriptletContext.putGlobal("Output", data);. Any variable  created through the scriptlet will not show up  in the step inspector for that step. In order to make sure that everything went ok  while debugging in the next step put a validator (ex: check null for that variable name). 



  • You should be able to use the scriptlet as you described.

    maybe the below document will help in understanding when that scritplet will be run. -

  • I've created a new flow that contains a Do Nothing step and a Succes response and created the transition.
    I have then created a scriptlet in Configuration\Scriptlets that contains the following:
    scriptletContext.put("zzz_test","Test Data");
    scriptletResult = "done";
    On the flows properties, I have dragged the above scriptlet onto the scriptlet pane.

    When I run the flow, the zzz_test variable is not created and the result is not set either, which indicates the shared scriptlet is not firing.
    If I switch to a custom scriptlet and copy the contents of the scriptlet in to the text area, when I run the flow again the variable is created and the result is set to 'done' as expected.

    Furthermore, if I check the underlying XML file for the flow, there is no mention of a scriptlet.



  • Hi,

    Is there a reason why  you want to run the scriptlet at the flow level?

    Scriptlets  (especially those that add variables to the context) should be used at step level not at flow level.  

    Ususally scriptlets are resolved last (after the curent entity finishes executing).  In the case of a flow this means that they are resolved after the execution is complete.  This in turn means that any scriptlet that modifies the  local context (adds/modifies variables) will be ignored when  resolving it. Any  scriptlet that modifies the global context will create/modify the global context, however the changes again will be available only once the execution ends.

    In order to add variables to the local context add the scriptlet to the first step in the flow execution.

    If you want i can also attach some examples for this.

    Hope this clears things up a bit,


  • In the example I provided I was trying to set a variable within the context, however, that was only for demonstration purposes to show that a shared scriptlet doesn't appear to fire when used in this way.

    What I'm actually trying to do is create a generic, reusable way of extracting step results from a flow for reporting purposes.

    I have prefixed the results I am interested in with oo_ and am using scriptletContext.keySet() to retrieve these results in to a JSON string which I am setting as the scriptletResult

    Doing this at the flow level is the logical place to do it  - when the flow ends all 'oo_' variables that have been created at that point will be available in the Result field in the resulting JSON, which can then be passed to other flows for converting to HTML and emailing out.



  • I figured this out.

    If the scriptlet box contains nothing when dragging on the shared scriptlet, it never gets fired.
    if I remove the shared scriptlet and add a space character to the scriptlet, then drag on the shared scriptlet, it will fire.

    It seems the scriptlet box must contain some static data to allow the shared scriptlet to run.

  • That doesn't always work (in 10.70 at least).  I've had just general strangeness with "shared scriptlets".  I get the impression that this isn't a much used feature in OO because when i vetted my observations with others in the community and all i heard was crickets.

    You're right though, something is definitely wrong with shared scriptlets (at least in OO 10.70).

  • We are using 10.70 and I can definitley replicate the issue each time. You can also check the underlying XML file for the flow consuming the scriptlet and you will see if it is going to work or not.

    1. Create a new flow, add a Do Nothing step and success response and wire them up.
    2. Open the flow properties, go to the scriptlet tab and drag on a shared scriptlet
    3. Save the flow and check the XML file generated, you will see no reference to the scriptlet.
    4. Switch back to a custom scriptlet and add any character to the scriptlet box (I choose a blank space)
    5. Drag the shared scriptlet back on to the scriptlet pane and save the flow
    6. Open up the XML again and you will see a scriptlet node, similar to the below:

      <scriptlet id="abe85193-47df-4a53-8348-ad62023613e2">
        <name>Operation TEMP FLOW (ed9f1cc3-3ea0-4fd4-9436-41fb3f3fc54e)</name>
        <script> </script>
          <refName>Test Shared Scriptlet</refName>

    7. To take this full circle, go back to the flow, switch back to a custom scriptlet, remove the blank space, add the shared scriptlet back and then save the flow. Open the XML and you will see there is no reference to the scriptlet.