Trusted Contributor.. sunts Trusted Contributor..
Trusted Contributor..
499 views

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.

Thanks

0 Likes
8 Replies
Micro Focus Expert
Micro Focus Expert

Re: Shared Scriptlets On A Flow

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). 

Regards,

Vlad

0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: Shared Scriptlets On A Flow

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. - https://drive.google.com/file/d/0B1VqSvJz11AbR3BpM19jR2dGeUE/view?usp=sharing

Andrei Vasile Truta
0 Likes
Trusted Contributor.. sunts Trusted Contributor..
Trusted Contributor..

Re: Shared Scriptlets On A Flow

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.

 

 

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Shared Scriptlets On A Flow

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,

Vlad

0 Likes
Trusted Contributor.. sunts Trusted Contributor..
Trusted Contributor..

Re: Shared Scriptlets On A Flow

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.

 

 

0 Likes
Trusted Contributor.. sunts Trusted Contributor..
Trusted Contributor..

Re: Shared Scriptlets On A Flow

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.

0 Likes
Micro Focus Expert
Micro Focus Expert

Re: Shared Scriptlets On A Flow

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).

0 Likes
Trusted Contributor.. sunts Trusted Contributor..
Trusted Contributor..

Re: Shared Scriptlets On A Flow

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">
    <annotation></annotation>
    <name>Operation TEMP FLOW (ed9f1cc3-3ea0-4fd4-9436-41fb3f3fc54e)</name>
    <script> </script>
    <type>NASHORN</type>
    <scriptRef>
      <refId>a5b0fe2b-d869-49bf-9be6-7b2a4ba05de2</refId>
      <refName>Test Shared Scriptlet</refName>
    </scriptRef>
  </scriptlet>

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.

 

 

 

 

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.