Highlighted
Contributor
Contributor

vRO 8.1 - Scriptable Task (Powershell) not passing "output" to next action as an "input"

Jump to solution

Hi all,

I have what is hopefully a simple problem.

I have a workflow which contains 2 actions - both are Powershell scriptable tasks.

What I am hoping to achieve is to return a value in action 1 (output) and have that value visible in action 2 (input).

My workflow looks like this:

Inputs/Outputs:

pastedImage_0.png

Action A:

pastedImage_1.png

pastedImage_2.png

Action B:

pastedImage_3.png

pastedImage_4.png

Workflow run outputs:

pastedImage_5.png

Action A, note the value "172.23.10.0" is returned - I expect this to be the output of action A

Action B - note that the "172.23.10.0" value nor a property name of "subnet" is visible in the inputs:

pastedImage_6.png

pastedImage_7.png

I'm sure I have missed something simple, I'm just not sure what it is and the vRO8.1 documentation Powershell action documentation has been no help in this case.

Thanks in advance

1 Solution

Accepted Solutions
Highlighted
VMware Employee
VMware Employee

Hi,

The way I've found for this (After some researching -- and based on vRA / vRO 8.1 - Return an array from Powershell ) was to convert the first script task (the one with output variable) to an action with return type Properties. This is my test action:

function Handler($context, $inputs) {

$ht1 = @{ A = 'a'; B = 'b'; DateTime = Get-Date }

$theObject = new-object psobject -Property $ht1

write-host $theObject

return $theObject

}

return type: Properties

My script task will receive the output generated by the action and, in my example, execute the following:

function Handler($context, $inputs) {

    $inputsString = $inputs | ConvertTo-Json

  Write-Host $inputsString

    Write-Host $inputs.tmp

    $output=@{status = 'done'}

    return $output

}

With input variable of type Properties (The one that generates the action)

Hope this helps.

Regards,

Leandro.

View solution in original post

0 Kudos
7 Replies
Highlighted
VMware Employee
VMware Employee

Hi,

The way I've found for this (After some researching -- and based on vRA / vRO 8.1 - Return an array from Powershell ) was to convert the first script task (the one with output variable) to an action with return type Properties. This is my test action:

function Handler($context, $inputs) {

$ht1 = @{ A = 'a'; B = 'b'; DateTime = Get-Date }

$theObject = new-object psobject -Property $ht1

write-host $theObject

return $theObject

}

return type: Properties

My script task will receive the output generated by the action and, in my example, execute the following:

function Handler($context, $inputs) {

    $inputsString = $inputs | ConvertTo-Json

  Write-Host $inputsString

    Write-Host $inputs.tmp

    $output=@{status = 'done'}

    return $output

}

With input variable of type Properties (The one that generates the action)

Hope this helps.

Regards,

Leandro.

View solution in original post

0 Kudos
Highlighted
Contributor
Contributor

Hi Leandro,

Thanks for the info - using the above example would you mind sharing the confirmation of Variables, Inputs, Outputs for the workflow also?

Thanks!

0 Kudos
Highlighted
VMware Employee
VMware Employee

Hi,

Of course. Let me add my screenshots here

Screenshot (739).png

Screenshot (738).png

I don't have input or output variables (The only variable I have is the one called tmp, that is associated to the action output variable and then used as imput for the script task)

Screenshot (740).png

Regards,

Leandro.

0 Kudos
Highlighted
Contributor
Contributor

Thankyou Leandro - you've helped me understand why this was not working.

That being said, it seems odd to me that an action can return a variable output, but a scriptable item cannot.

Cheers

0 Kudos
Highlighted
VMware Employee
VMware Employee

lowlysysadminlnairn The screenshots are a bit low res so I could not figure out the script that you provided, but I think you have found a workaround, while good enough, there is a way to handle it natively. So the way actions and scriptable tasks (inline in the workflow),  even before 8.1 with the classical javascript, is:
1. Actions return a single (unnamed) value
2. Scriptable tasks return multiple named values

To accommodate the new runtimes like powershell to the above model, where a powershell function returns a single value one would do:
1. For actions, straightforwards - return the value

2. For scriptable tasks - return a map of values, where the key is the name of output parameter you want to set and the value is the value which you want to set

So if you use scriptable tasks and have a variable in your workflow "myVar". In your first script you would bind the output of myVar -> to myVar. The in the powershell script you would return @{myVar = 'the value'}

Then in the next scriptable task you would bind the variable myVar to your input myVar, and access it in powershell like $inputs.myVar

Highlighted
Enthusiast
Enthusiast

So if you use scriptable tasks and have a variable in your workflow "myVar". In your first script you would bind the output of myVar -> to myVar. The in the powershell script you would return @{myVar = 'the value'}

Hi, What is the variable type of myVar in the workflow?

thanks,

ds

0 Kudos
Highlighted
VMware Employee
VMware Employee
What is the variable type of myVar in the workflow?

In this example it is of type string, but other supported are number, boolean, Properties/Composite Type...

0 Kudos