Using JSON Parser on Array.Object in Flow Designer

TramaineM
Kilo Sage

Hello,

I recently created an Action in Flow Designer that uses JSON Parser to get some custom field variables on a JSON. This worked great and I was able to get my output variables. However, there were a few more custom fields that I needed to have an output variable for and it's not letting me since its in an Array.Object. 

I'm not good at scripting but I created a Script Step to get these fields but its not working. 

I've tried making the input variable the payload and going straight to the array.object data pill. When making the input the array.object data pill, it gives me an "Error: u,Detail: Unexpected token: u" when doing the test. When making the input the root payload from the JSON Parser step, it gives me an "Error: o,Detail: Unexpected token: o". 

 

19 REPLIES 19

Someone with a similar issue: https://community.servicenow.com/community?id=community_question&sys_id=462854d2dbb0d340b61ff3231f96...

Does your runtime values give any clue to undefined string value?

Sorry for the late reply. But no, the runtime values are completely blank. 

I tried adjusting the input back to the payload and adjusting the script. I get different errors when testing so I just published it into the subflow I want and now I'm getting a whole new error. 

Error: "console" is not defined.,Detail: "console" is not defined.

find_real_file.png

Chris Sanford
Giga Guru

Ok so if there's an array in the payload you're going to need to call a forEach loop on it, you can't just dot-walk to fields in an Array.object, as there is possibly several objects in the array with that same field. If you send me a sample of what the payload looks like I could help you further

Hey Chris, it can never be that simple lol. Thanks for your reply. Here is the snippet that is coming over as an array. I'm just trying to get the id, boardId, start and end date. If you need the entire payload, let me know.

Issue

   Fields

    "customfield_10010": [
     {
           "id": 1064,
           "name": "Demo Sprint",
           "state": "active",
           "boardId": 201,
           "goal": "This is a Demo",
           "startDate": "2021-03-17T18:09:00.000Z",
            "endDate": "2021-03-24T18:09:00.000Z"
       }
],

find_real_file.png

Ok so yeah like first thing you should try because it might be that simple.

  1. Remove the script step and just use json parse step
  2. then in your subflow add a "For each" flow logic
  3. now when it asks you for "items" drag your Array.object custom field data pill from your custom action into it.
  4. Then you can access the fields inside the "For each" block of subflow

if that doesn't work and we have to do script, let me know.