Maybe that will help you. Please take a look closely to the inputs and outputs configuration.
If you find the answer helpful, please click on the RECOMMEND button.
Original Message:
Sent: Jul 14, 2025 08:37 AM
From: Michael Cornn
Subject: In Workflows, Scriptable Tasks do not assign values to variables. The same code in an action does so.
Thanks for the reply. Even after changing "return output;" to "System.log(output[0]);" the variables are not set.
The value of the 'output' variable is logged, but 'jsScriptArray' workflow variable is 'Not set'.
I think I resolved the issue, though. I can reference (and set the value of) workflow variables in the scriptable tasks. The adjusted snippet below sets the variables properly.
//JavaScript//jsScriptArray is set as an outputvar output = new Array();output.push('hello');output.push('world');//System.log(output);System.log(output[0]);jsScriptArray = output;
Sadly, this doesn't work in PowerShell. Which is bad for me, because I need to perform a task in PowerShell. This updated code snippet does not set the variable at all.
function Handler($context, $inputs) { #PowerShell #Workflow variable psScriptArray is set as both an input and output $inputsString = $inputs | ConvertTo-Json -Compress $output = @() $output+='hello' $output+='world' $inputs.psScriptArray = $output Write-Host $inputs.psScriptArray #Log output display 'hello world' #However, the workflow variable psScriptArray is not changed }
Original Message:
Sent: Jul 11, 2025 05:03 PM
From: WhiteForEver
Subject: In Workflows, Scriptable Tasks do not assign values to variables. The same code in an action does so.
Hey Michael,
The reason for that is that "return" should only be used in Action Elements because, as you rightly mentioned, Action Elements are used for reusable code (which in most cases is a function). Action Element in vRO world is technically an Immediately Invoked Function Expression, commonly abbreviated as IIFE in JS world. You can find more info in Google.
In the scriptable task, you shouldn't use "return". If you want to see the value or the "output" in the scriptable task, simply use "System.log(output[0])."
The error you're getting originates from the scriptable task number 15, which contains plain JavaScript code without any functions.
The reason you're not getting any errors from your "PS" code in the scriptable task 14 is that it's enclosed within a function. The "Return" statement inside the function within the scriptable task is a valid piece of code. I suppose nothing is calling that function within the scriptable task either, so technically, this scriptable task does nothing, but that's not directly related to the issue :)
------------------------------
If you find the answer helpful, please click on the RECOMMEND button.
Please visit my blog to get more information: https://clouddepth.com
Original Message:
Sent: Jul 11, 2025 04:03 PM
From: Michael Cornn
Subject: In Workflows, Scriptable Tasks do not assign values to variables. The same code in an action does so.
Why does the same code produce different results in scriptable tasks versus actions?
I wrote this PowerShell code:
function Handler($context, $inputs) {
$inputsString = $inputs | ConvertTo-Json -Compress
$output = @()
$output+='hello'
$output+='world'
return $output
}
I wrote this code in JavaScript:
var output = new Array();
output.push('hello');
output.push('world');
return output;
I pasted these code snippets into actions. I put the two actions in a workflow.
Then I pasted the same snippets in two scriptable tasks in the workflow.
I made four variables (jsActionArray, jsScriptArray, psActionArray, and jsActionArray), setting their types to Array/string.
When I ran the workflow, the two actions produced the expected output: A String array with elements 'hello' and 'world'.
The scriptable PowerShell task, however, produced no output. The psScriptArray is null.
The scriptable JavaScript task actually produced an error "Invalid return."
This doesn't make sense to me. The same code should produce the same results, whether that's a workflow action or a workflow scriptable task. My assumption is that scriptable tasks are for "one-off" code snippets that won't be reused in other workflows, whilst actions are "function" code that can be reused between multiple workflows. Is there another difference I should be aware of?
Screenshots: