IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
Expand all | Collapse all

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

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

    Posted 06/04/21 09:01 AM

    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"
    }
    }
    }
    }
    }
    

    #webMethods-io-Integration
    #webMethods


  • 2.  RE: How to output an Array in webMethods.io Custom Action with Node.js

    Posted 06/07/21 03:49 AM

    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);
    }
    
    }
    

    #webMethods
    #webMethods-io-Integration