cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Javascript Snippet output not a useable list for subsequent steps

nick_CCEP
Deputy Chef I
Deputy Chef I

Can anyone assist in getting my JSON structure from within a Javascript snippet to be a useable list to iterate through?  no matter how I try to 'return' an object or array in the Javascript snippet step, there is no data structure to use in subsequent steps.  I am just using a test situation after trying in vain with my actual recipe, and even a simple JSON array makes no difference.  

Workato documentation is woefully lacking so I have no idea how to assign things to the output variables, I only have experience using the 'return' function.  I have taken screenshots but can't seem to upload them to this message either, sorry!

Thanks in advance
Nick

2 REPLIES 2

timwolfe
Deputy Chef I
Deputy Chef I

Here's an example of a simple JavaScript snippet that returns a JSON array:

// Define your data as an array of JSON objects
let items = [
{ id: 1, name: "Item 1" },
{ id: 2, name: "Item 2" },
{ id: 3, name: "Item 3" }
];

// Return the array
return items;

timwolfe
Deputy Chef I
Deputy Chef I

If you're working with a stringified JSON and need to parse it, you can do:

// Example of stringified JSON input
let input = '[{"id": 1, "name": "Item 1"}, {"id": 2, "name": "Item 2"}]';

// Parse the string to JSON
let parsedData = JSON.parse(input);

// Return parsed data
return parsedData;