Output only the 1st value from an Array

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

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

1 Like

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.

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

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

1 Like

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