Return / share a map-like object from a custom action

ILYA STEIN
Tera Guru

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:

ILYASTEIN_0-1761732519402.png

And test results:

ILYASTEIN_1-1761732624349.png

 

2 REPLIES 2

Sarthak Kashyap
Tera Guru

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

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...