Legacy Dev Forum Posts

 View Only

Sign Up

  • 1.  Count of records returned

    Posted 06-05-2025 18:41

    Lloyd | 2020-06-23 20:19:22 UTC | #1

    I've built a data action performing a contact lookup for ServiceNow. What I'd like to do is count the number records returned so I know if I had a single or multiple match.

    My returned Data looks like this:

    { "records": [ { "name": "personA" }, { "name": "personB" }, { "name": "personC" } ] }

    My current work around is to look for a 2nd record and have a translationMapDefault value of "No" if there isn't one.

    In my Architect flow I check if contact_two='No' then I know it was single match

    { "translationMap": { "rawName": "$.records[0].name", "rawContacttwo": "$.records[1].name" }, "translationMapDefaults": { "rawContacttwo": "\"No\"" }, "successTemplate": "{\n \"name\": ${rawName}\n, \"contacttwo\": ${rawContacttwo}\n }" }

    But I was hoping there was a more elegant way of achieving this by just counting the records and returning the count value

    Thanks


    Jerome.Saint-Marc | 2020-06-24 07:17:52 UTC | #2

    Hello,

    I didn't remember or didn't know... It appears that the size() function can be used on Arrays (in the Data Action Response Configuration). It can count the number of elements/objects in the array.

    I mean something like this:

    { "translationMap": { "rawName": "$.records[0].name", "rawContactCount": "$.records.size()" }, "translationMapDefaults": { "rawContactCount": "0" }, "successTemplate": "{\n \"name\": ${rawName}\n, \"contact_count\": ${rawContactCount}\n }" }

    With contact_count being defined as an Integer in your Data Action Output Contract.

    Regards,


    Lloyd | 2020-06-25 20:30:29 UTC | #3

    Jerome,

    That's excellent. Thank you.


    system | 2020-07-26 20:30:30 UTC | #4

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


    This post was migrated from the old Developer Forum.

    ref: 8092