Legacy Dev Forum Posts

 View Only

Sign Up

Output only the 1st value from an Array

  • 1.  Output only the 1st value from an Array

    Posted 06-05-2025 18:46

    Angela_Garzon | 2024-07-30 20:17:11 UTC | #1

    I'm trying to Output the 1st value from a nested array. I only want to see this value from the PortalCode return: "CAMBRI"

    Here is the Contract:

    Here are the Output fields:

    My basic translationMap: { "translationMap": { }, "translationMapDefaults": {}, "successTemplate": "${rawResult}" }


    zubair | 2024-07-30 21:26:53 UTC | #2

    If you are calling this data action in an architect flow, then the simplest solution is to use values of Discount.PortalCodes at index 0 i.e. variableName[0] where variableName is the variable storing the Discount.PortalCodes output in your flow


    Jason_Mathison | 2024-07-31 12:33:30 UTC | #3

    In order to configure your translationMap to gather just the value that you want, I suggest taking the output of the "Execution" step and pasting it into https://www.javainuse.com/jsonpath to work out exactly what your jsonpath should be.


    Angela_Garzon | 2024-08-01 15:09:36 UTC | #4

    I was able to update the translationMap to:

    {
      "translationMap": {
        "PortalCodes": "[0].Discount.PortalCodes[0]"
      },
      "translationMapDefaults": {},
      "successTemplate": "${rawResult}"
    }

    and in the Resolve I see the Key/value expected, but I can't seem to get the correct successTemplate so that I see it in the Output.

    {
      "rawResult": "[ {\n  \"PersonID\" : 4552604,\n  \"FirstName\" : \"xxx\",\n  \"MI\" : \"\",\n  \"LastName\" : \"xxx\",\n  \"Suffix\" : \"\",\n  \"Prefix\" : \"\",\n  \"PrimaryOrFirstEmailAddress\" : \"xxx.xxx@zoeh.org\",\n  \"Inactive\" : false,\n  \"IsBillableAccount\" : false,\n  \"IsAuthorizedEnroller\" : false,\n  \"IsFraud\" : false,\n  \"LastOrderDate\" : \"/Date(1721232947830)/\",\n  \"PrimaryAddress\" : {\n    \"AddressNumber\" : 3,\n    \"AddressID\" : 4552607,\n    \"AddressPriorityCode\" : \"P\",\n    \"ShipToName\" : \"xxx xxx\",\n    \"ShipToPhone\" : \"xxx-120-5159\",\n    \"ShipToEmail\" : \"xxx.xxx@xxx.org\"\n  },\n  \"Discount\" : {\n    \"PromoCodes\" : [ ],\n    \"PortalCodes\" : [ \"CAMBRI\", \"CambriPre\", \"CIR2\" ]\n  },\n  \"PurchasingCode\" : \"\",\n  \"MarketingIdentifiers\" : [ {\n    \"Name\" : \"EWC\"\n  } ]\n} ]",
      "PortalCodes": "\"CAMBRI\""
    }

    Angela_Garzon | 2024-08-02 17:55:22 UTC | #5

    I found the solution and wanted to post in case this helps anyone else. Changed the Output Contract to:

    Translation Map to:

    {
      "translationMap": {
        "FirstName": "$[0]['FirstName']",
        "LastName": "$[0]['LastName']",
        "PrimaryOrFirstEmailAddress": "$[0]['PrimaryOrFirstEmailAddress']",
        "PersonID": "$[0]['PersonID']",
        "PortalCode": "$[0]Discount.PortalCodes[0]",
        "ResultCount": "$.size()"
      },
      "translationMapDefaults": {
        "FirstName": "\"\"",
        "LastName": "\"\"",
        "PrimaryOrFirstEmailAddress": "\"\"",
        "PersonID": "\"\"",
        "PortalCode": "\"\"",
        "ResultCount": "0"
      },
      "successTemplate": "{\"FirstName\": ${FirstName}, \"LastName\": ${LastName}, \"PrimaryOrFirstEmailAddress\": ${PrimaryOrFirstEmailAddress}, \"PersonID\": ${PersonID}, \"PortalCode\": ${PortalCode}, \"ResultCount\": ${ResultCount}}"
    }

    Output:


    system | 2024-09-02 17:55:31 UTC | #6

    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: 27490