h_poo
Visitor.
952 views

Execute Flow from Scriptlet

Jump to solution

Is there anyway to execute a OO Flow from a JavaScript (Rhino) scriptlet?

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Re: Execute Flow from Scriptlet

Jump to solution

Launching a flow in OO is just a REST call, which is documented in the OO API Guide; it boils down to an HTTP POST with a JSON body.  The API Guide gives the following example:

{
  "flowUuid":"8d52dfc3-1de5-48d4-9c2a-887718de4696", "runName": "run1",
  "logLevel": "STANDARD",
  "inputs":
  {  "input1":"value for input1",   ....... "inputn":"value for inputn" }
}

The problem is that a flow's scriplet context doesn't have the XMLHttpRequest class loaded (an AJAX class) meaning it's non-trivial to do HTTP requests directly from javascript..  You could try to find a minified version of an HTTP request library or you could just use what comes OOTB in OO., of which, there are two:

  1. Use an "HTTP Client 2.0" operation  with method "POST", and craft the json body manually
  2. Use the "Dynamicaly Launch Flow" operation. (/HPE Solutions/Library/Integrations/Hewlett-Packard/Operations Orchestration/10.x/Dynamically Launch Flow} and supply the relevant inputs

I've used both methods but I tend to use the "Dynamically Launch Flow" operation for convenience (rather than performance) in a loop and use a "Do Nothing With 2 Responses" with a scriplet to create the  dynamic variables for the inputs.  

Even if you do manage to get an HTTP request working in a scriptlet, you need to authenticate with OO to make the request.  This means that you will need to be able to get a service account username/password from inside the scriptlet.  There are challenges with this too if the  step input is a "Sensitive Data" field because the data comes in encrypted (and you have to refer to the input by name - you can't use scriptletContext.get('inputname') to get the value).

 

 If you're going to start lots and lots of flows, with dynamic inputs, you can also write an external application to do it for you and then just use a remote command to execute that program. 

Ironically, if you want maximum performance for starting flows in OO, this is the best way to do it.  HTTP Client and Dynamically Launch Flow operations are slow.  Depending on your environment/hardware, they can take anywyere between 1-3 seconds to kick off a new flow.  But using an external flow execute method (like wget, python http requsets, etc), you can start a flow in 0.5-1s (though it still takes more time than that for the actual flow to start - but you will get the requests completed more quickly).

5 Replies
Micro Focus Expert
Micro Focus Expert

Re: Execute Flow from Scriptlet

Jump to solution

Launching a flow in OO is just a REST call, which is documented in the OO API Guide; it boils down to an HTTP POST with a JSON body.  The API Guide gives the following example:

{
  "flowUuid":"8d52dfc3-1de5-48d4-9c2a-887718de4696", "runName": "run1",
  "logLevel": "STANDARD",
  "inputs":
  {  "input1":"value for input1",   ....... "inputn":"value for inputn" }
}

The problem is that a flow's scriplet context doesn't have the XMLHttpRequest class loaded (an AJAX class) meaning it's non-trivial to do HTTP requests directly from javascript..  You could try to find a minified version of an HTTP request library or you could just use what comes OOTB in OO., of which, there are two:

  1. Use an "HTTP Client 2.0" operation  with method "POST", and craft the json body manually
  2. Use the "Dynamicaly Launch Flow" operation. (/HPE Solutions/Library/Integrations/Hewlett-Packard/Operations Orchestration/10.x/Dynamically Launch Flow} and supply the relevant inputs

I've used both methods but I tend to use the "Dynamically Launch Flow" operation for convenience (rather than performance) in a loop and use a "Do Nothing With 2 Responses" with a scriplet to create the  dynamic variables for the inputs.  

Even if you do manage to get an HTTP request working in a scriptlet, you need to authenticate with OO to make the request.  This means that you will need to be able to get a service account username/password from inside the scriptlet.  There are challenges with this too if the  step input is a "Sensitive Data" field because the data comes in encrypted (and you have to refer to the input by name - you can't use scriptletContext.get('inputname') to get the value).

 

 If you're going to start lots and lots of flows, with dynamic inputs, you can also write an external application to do it for you and then just use a remote command to execute that program. 

Ironically, if you want maximum performance for starting flows in OO, this is the best way to do it.  HTTP Client and Dynamically Launch Flow operations are slow.  Depending on your environment/hardware, they can take anywyere between 1-3 seconds to kick off a new flow.  But using an external flow execute method (like wget, python http requsets, etc), you can start a flow in 0.5-1s (though it still takes more time than that for the actual flow to start - but you will get the requests completed more quickly).

Micro Focus Contributor
Micro Focus Contributor

Re: Execute Flow from Scriptlet

Jump to solution

What you can do is trigger a flow that is already deployed in OO through the trigger api. In the scriplet you need to write an ajax call to OO that triggers the flow. The flow triggering API documentation is available here:  https://docs.microfocus.com/itom/Operations_Orchestration:10.80/Develop/Working_with_API/Execute_a_Flow_by_UUID

Luis_V_OO Super Contributor.
Super Contributor.

Re: Execute Flow from Scriptlet

Jump to solution

Hello,

           There is also another way to fire a flow by using PowerShell.  

The PowerShell code below will show you how you can execute an OO flow thru the API from PowerShell. It fires 3 different flows. 

 

$username = "internal\testAPI"

$password = "testAPI"

$pair = "${username}:${password}"

$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)

$base64 = [System.Convert]::ToBase64String($bytes)

$basicAuthValue = "Basic $base64"

 

$executeHeaders = @{

    "Authorization" = $basicAuthValue

    "Content-Type" = "application/json"

    "Accept" = "application/json"

}

 

$json = '{"flowUuid":"":"<the flow UUID>"}'

try{

    $response = Invoke-RestMethod -Method POST -Uri "https://localhost/oo/rest/v2/executions/" -Headers $executeHeaders -Body $json -TimeoutSec 10

    write-host "$json - $response"

}

catch {

    $exceptionDetails1 = $_.Exception

    Write-Host "Error Invoking RestMethod $executeurl "

    Write-Host $exceptionDetails1

    exit 1002

}

 

$json = '{"flowUuid":"":"<the flow UUID>"}'

try{

    $response = Invoke-RestMethod -Method POST -Uri "https://localhost/oo/rest/v2/executions/" -Headers $executeHeaders -Body $json -TimeoutSec 10

    write-host "$json - $response"

}

catch {

    $exceptionDetails1 = $_.Exception

    Write-Host "Error Invoking RestMethod $executeurl "

    Write-Host $exceptionDetails1

    exit 1002

}

 

$json = '{"flowUuid":"<the flow UUID>"}'

try{

    $response = Invoke-RestMethod -Method POST -Uri "https://localhost/oo/rest/v2/executions/" -Headers $executeHeaders -Body $json -TimeoutSec 10

    write-host "$json - $response"

}

catch {

    $exceptionDetails1 = $_.Exception

    Write-Host "Error Invoking RestMethod $executeurl "

    Write-Host $exceptionDetails1

    exit 1002

}

 

 

I hope this information helps!

 

Regards,

Luis Quiros
Customer Support Engineer

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution.
If you are satisfied with anyone’s response please remember to give them a KUDOS by clicking on the STAR at the bottom left of the post and show your appreciation.
h_poo
Visitor.

Re: Execute Flow from Scriptlet

Jump to solution

Thanks David.

 I was afraid this would be the only solution. Due to client restrictions around installing 3rd party libraries, I will likely need to execute a REST POST using wget/curl.

If I had enough time, I'd like to reverse engineer the product, as I'm sure I would be able to find and use Java POJO's to run a flow.

Cheers
Darcy

0 Likes
FMorales
New Member.

Re: Execute Flow from Scriptlet

Jump to solution

Luis,

If you happen to see this do you mind elaborating on why this works? I've been beating my head against the wall because the API guide says in order to issue a POST request and start the execution of a flow, I must supply a valid CSRF token. I'm also using PowerShell and can get the token fine (Using a GET request via Invoke-WebRequest to read the response headers). I can add it to the headers for the subsequent POST call (using a Proxy I verified it was indeed sent) however every time HPOO 10.60 gives an error about a missing CSRF token. (I did a test client in C# to verify, and got the same missing token error)

I tried using my "Community Edition" test setup to verify and I get the same error. After seeing your post today I tried it and sure enough if I simply omit the initial GET and copying of the 'X-CSRF-TOKEN' into the headers, and simply do the POST, it works just fine. I'm glad it's working, but since my team needs to automate the execution of several flows, I wanted to make sure this behavior can be relied upon. 

NOTE: IIRC in the docs, CSRF protection is on by default, including in my Community Edition test setup. For sure it has not been disabled in my CE test lab environment, and while I don't control production I'm not aware of it changing there either.

Any help would be greatly appreciated when you/someone has a moment, thanks,

Frank...

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.