How to output an Array in webMethods.io Custom Action with Node.js

Hi, I’m to creating a custom action that outputs an object, and one of the properties of this object is an array. Now I’m specifying my ‘this.output’ object, but as soon as I add the array - the action won’t compile anymore. If I remove the array, everything compiles just fine.

Any idea of how to fix this?

A little simplification of what I have right now:

this.output = {
        "title" : "output",
        "type" : "object",
        "properties":{
            "header":{
                "title":"header",
                "type" :"object",
                "properties": {
                ...
                }
            },
            "data": {
                "title":"data",
                "type":"object",
                "properties": {
                    "length": {
                        "title":"length",
                        "type":"string"
                    },
                    "dataArray":{                       // <--------------
                        "title":"dataArray",
                        "type":"array"
                    }
                }
            }
        }
}

Hi Lars,

You can use the “map” to map your array of data to the output in this.execute block.

Syntax goes likes this - ArrayofDataNeededAsOutput.map(obj => {
let rObj
rObj= obj
return rObj
});

Sample snippet for reference below

Basically the below code is just mapping the values from input array to output array in this.execute section.

var request = require ("request");


module.exports = function(){

    this.input = {
        "title": "Sample input",
        "type": "object",
        "properties": {
      
            
             userArray: {
        type: "array",
        title: "Array",
        minItems: 1,
        items: {
          type: "object",
          title: "Index",
          properties: {
            name1: {
              type: "string",
              title: "Item1",
              minimum: 1,
              description: "Enter the item"
            },
            name2: {
              type: "string",
              title: "Item2",
              minimum: 1,
              description: "Enter the item"
            },
          }
        },
      },
            
            
        }
    }; 


    this.output = {
        "title" : "output",
        "type" : "object",
        "properties":{
            "status":{
                "title":"status",
                "type" :"string"
            }
        }
    }; 



   this.execute = function(input,output){
   const map1 = input.userArray.map(obj => {
   let rObj
   rObj= obj
   return rObj
});
        
            return output(null,map1);
    }

}
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.