Return / share a map-like object from a custom action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago - last edited 6 hours ago
I have a custom action that creates a map-like object (as in {'a': 'Alpha', 'b': 'Bravo', 'c': 'Charlie', ...}) with a variable number of elements, which I would like to store in a flow variable and share to subsequent steps. When I try to return the map as an 'Object' output type, it is returned empty. I can return it as a stringified JSON in a String output, but would like to avoid having to convert the map to and from JSON string every time I need to use it. What would the proper way be to return the actual map object?
Here is a simplified code example:
And test results:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Hi @ILYA STEIN ,
Please try to use below code
function execute(inputs, outputs) {
var map = {
a: 'Alpha',
b: 'Bravo',
c: 'Charlie',
d: 'Delta'
};
var arrayOutput = [];
for (var key in map) {
arrayOutput.push({ key: key, value: map[key] });
}
outputs.results = arrayOutput; // Output type: Array of Objects
outputs.message = map;
}
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
6 hours ago
Are you suggesting that I should return an array of objects rather than an object? I thought about that option, but again, i would like to use the map as is and not have to convert it for each use...
