Data Action & TranslationMap Help

Hello,

I'm hoping that someone can shed some light on the following data action and implementing the translation map.

I have the Input Contract as follows
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Account Details Request",
"description": "Account GUID request for customer data.",
"type": "object",
"properties": {
"accountnumber": {
"type": "string"
}
},
"additionalProperties": true
}

The output contract is as follows:

{
"description": "This is the contract that will be enforced. See the success template for how this is produced. Returns the full response.",
"type": "array",
"properties": {},
"items": {
"title": "Item 1",
"type": "object",
"properties": {
"BeneficiaryGuid": {
"type": "string"
}
},
"additionalProperties": true
}
}

The translation mapping that i put together is as follows.
{
"translationMap": {
"BeneficiaryGuid": "$.BeneficiaryGuid"
},
"translationMapDefaults": {
"BeneficiaryGuid": ""
},
"successTemplate": "{\n "BeneficiaryGuid": ${BeneficiaryGuid} \n}"
}

Whenever i run the test, I'm getting the following error message:
10. Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unexpected character ('}' (code 125)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (String)"{ "BeneficiaryGuid": }"; line: 3, column: 2]' Template:'{ "BeneficiaryGuid": ${BeneficiaryGuid} }'.

I checked the mapping in JSON Online Validator and Formatter - JSON Lint and it's valid. So, I'm not sure what exactly I'm missing here.

Any help that you can provide would be greatly appreciated.

Try this

"successTemplate": "{\n \"BeneficiaryGuid\": ${BeneficiaryGuid} \n}"

Hi Zubair,

I tried it and it's throwing the same error.

Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unexpected character ('}' (code 125)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (String)"{ "BeneficiaryGuid": }"; line: 3, column: 2]' Template:'{ "BeneficiaryGuid": ${BeneficiaryGuid} }'.

Hi @Christopher_Andre

Had a further look and your output contract does not look right, suspect that's where the problem might be. Are you able to share the sample schema of source data (redact any sensitive information) and the value(s) you are trying to retrieve?

Hi zubair, I've attached the sample of the source data and the data action as well.

response_accnum.json (4.2 KB)
Beneficiaries-Copy-2023102482449.custom.json (1.5 KB)

@zubair
I've also noticed that If I put the response to default, I get a different error message.
{
"translationMap": {},
"translationMapDefaults": {},
"successTemplate": "${rawResult}"
}

I get the following:

13. Flatten: Too many results matched criteria.

If I uncheck, flatten output, I get the following


but I realize that it's not picking up all the BeneficiaryGuid that i'm looking for.

@Christopher_Andre
So in the response, you expect multiple Beneficiaries against a single account number? try following changes

Use below Output Contract

{
  "description": "This is the contract that will be enforced. See the success template for how this is produced. Returns the full response.",
  "type": "object",
  "properties": {
    "BeneficiaryGuid": {
      "type": "array",
      "items": {
        "title": "Item 1",
        "type": "string"
      }
    }
  },
  "additionalProperties": true
}

and use following mapping under translationMap in the Response

    "BeneficiaryGuid": "$[*].BeneficiaryGuid"

See how you go

@zubair I really appreciate the help. It's working now.

@zubair One last question. How can I narrow down my results?

I tried for example $[3].BeneficiaryGuid to pull the data for the 4th beneficiary

@zubair
I created a filter
"arrayRelationshipWithHOH": "$[?(@.RelationshipWithHOH =='Self')].RenewalDate",

and the success template would be "myRenewalDate": {successTemplateUtils.firstFromArray("{arrayRelationshipWithHOH}")}

Hi Chris,
Yes that's the right filter to get data for a specific beneficiary.

Cheers

@zubair

The thing that I'm seeing is that the filter is hardcoded, and I would need to do the same for the other beneficiaries. Is there a different approach that I can use?
For example, I'm collecting the beneficiary phone number as well. I'm looking to use the phone number or other variable to retrieve the correct beneficiary. I'm seeing that with my approach of using the filter that could be problematic.

In that case I wouldn't add any filters in Data Action and retrieve all the information needed for all the Beneficiaries e.g. GUIDs, Relationships, Dates, Phone Number and any other data of interest. Then in the Architect Flow (assuming you are calling the data action in a Flow) you can use the Loop (use the Length() function for Max Loop Count) to extract the data of your interest from the Array and save it to variables. For example, in the loop you can find the index where RelationshipWithHOH =="Self" then all others values at that index will be related to that Beneficiary.

I'm calling the Data Action in the architect flow but I'm seeing two errors.
'==' at position 21 : There is no implementation that accepts parameters of String Collection and String.

I tried using the loop Until after the success from the Call Data Action but it's throwing the above error where I'm using an If statement to see if the Task.MobilePhone == call.ani

I'm wondering if I need to use Update Data to convert my Task.MobilePhone or is there a better way of doing this?

What expression are you using that throws above error? Seems like you are using two variables in expression where one is String Collection (Array) and other is just string so that's why you getting error. You will have to use same type of variable in expression

What type of Flow are you using here that does not recognize Call.Ani? Also what expression you are trying to use? If you give me an idea then I can help with the expression.

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