04-21-2021 09:52 PM
We need to merge multiple documents to single array and looking for help. Since it is ultra task, we are running out of options…
Input data:
[
{“Record”: “1”},
{“Record”: “2”},
{“Record”: “5”},
{“Record”: “4”},
{“Record”: “6”}
]
Expected Output:
[ “response”: [{“Record”: “1”}, {“Record”: “2”}, {“Record”: “5”}, {“Record”: “4”}, {“Record”: “6”}]
]
04-22-2021 08:07 AM
Hello @thilkip,
You can try and use Group by N snap. Set the group size to 0 and this is what you get:
Regards,
Bojan
04-22-2021 08:08 AM
yes, but Group by is not supported in Ultra tasks
04-22-2021 08:11 AM
Sorry, I missed that information.
04-22-2021 08:14 AM
We tried with script as below. it works in design mode but not when we call ultra tasks. When we call ultra tasks the script snap doesnt provide any output
execute : function () {
this.log.info(“Executing Transform Script”);
var outDoc = new LinkedHashMap();
var inDoc=null;
var items = new ArrayList();
var i=0;
while (this.input.hasNext())
{
try {
// Read the next input document, store it a new LinkedHashMap, and write this as an output document.
// We must use a serializable Java type liked LinkedHashMap for each output instead of a native
// JavaScript object so that downstream Snaps like Copy can process it correctly.
inDoc = this.input.next();
i=i+1;
items.add(inDoc);
outDoc.put("index", i);
if ((!this.input.hasNext()) || (this.input.hasNext()==false))
{
outDoc.put("data", items);
this.output.write(inDoc, outDoc);
}
}
catch (err) {
var errDoc = new LinkedHashMap();
errDoc.put("error", err);
this.log.error(err);
this.error.write(errDoc);
}
}
this.log.info("Script executed");