The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Returning Array of objects from response body via Integration HUB

IronPotato
Mega Sage

Hi All,

 

I'm calling REST API via integrationHUB and when I'm parsing the body I'm unable to get proper output. Which should be var results = [{}], so array of objects.

 

Script

IronPotato_0-1697123511429.png

 

Here are my output variables (can anyone explain what is the Results_child variable that is created automaticaly?)

IronPotato_2-1697123657891.png

 

Everything works fine and I'm getting the data until I try to put it into object. So as soon as I wrap the data in curly bracers inside push method, the result array is empty object.

 

{
    "Results": [
        "Zengeon",
        0,
        0,
        "2019-01-18",
        "Vitamin Connection",
        0,
        0,
        "2020-02-20",
        "WARRIOR SPIRIT",
        0,
        0,
        "2021-01-01",
        "Half-Life: Absolute Zero",
        0,
        0,
        "2017-04-17"
    ]
}

 

Any help would be appreciated.

 

Thank you

Tomas

 

1 ACCEPTED SOLUTION

@IronPotato Please refer to this page https://docs.servicenow.com/bundle/sandiego-application-development/page/administer/flow-designer/ta...

 

where starting from point #18 the entire step to create a complex object which is ultimately assigned to an array has been mentioned. 

 

Hope this helps.

View solution in original post

11 REPLIES 11

Sandeep Rajput
Tera Patron
Tera Patron

@IronPotato Please update the line number 7 as follows.

 

games.push({'name':game.name,'rating':game.rating,'playtime':game.playtime,'released':game.released});

In a nutshell, the object can be formed by providing key/value pairs. 

 

Hope this help.

Hi @Sandeep Rajput,

 

as mentioned above, as soon as I want to create proper object it will return results with 1 empty object

 

IronPotato_1-1697180947927.png

 

 

 

IronPotato_0-1697180933116.png

 

@IronPotato Could you add a gs.info(JSON.stringify(games)); and check if there is any issue with the way we are creating the object or if the issue lies within the output object.

@Sandeep Rajput ,

 

here's the log:

 

IronPotato_0-1697185958300.png