Legacy Dev Forum Posts

 View Only

Sign Up

Data Action & TranslationMap Help

  • 1.  Data Action & TranslationMap Help

    Posted 06-05-2025 18:44

    Christopher_Andre | 2023-10-23 20:21:03 UTC | #1

    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.


    zubair | 2023-10-24 01:55:49 UTC | #2

    Christopher_Andre, post:1, topic:22701
    "successTemplate": "{\n "BeneficiaryGuid": ${BeneficiaryGuid} \n}"

    Try this

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


    Christopher_Andre | 2023-10-24 02:41:10 UTC | #3

    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} }'.


    zubair | 2023-10-24 02:51:29 UTC | #4

    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?


    Christopher_Andre | 2023-10-24 12:29:52 UTC | #5

    zubair, post:4, topic:22701
    the sample schema of source data

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

    [response_accnum.json

    attachment](upload://rsSz2V1K0yOh5kc2FsLA1UAOgR.json) (4.2 KB)

    [Beneficiaries-Copy-2023102482449.custom.json

    attachment](upload://zh0vEp6dQdXz1Tz6hSkHaTaaT6O.json) (1.5 KB)


    Christopher_Andre | 2023-10-24 13:27:42 UTC | #6

    @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.


    zubair | 2023-10-24 18:23:14 UTC | #7

    @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


    Christopher_Andre | 2023-10-24 22:05:47 UTC | #8

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


    Christopher_Andre | 2023-10-25 13:10:06 UTC | #9

    @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


    Christopher_Andre | 2023-10-25 14:43:15 UTC | #10

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

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


    zubair | 2023-10-25 18:51:23 UTC | #11

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

    Cheers


    Christopher_Andre | 2023-10-25 19:46:41 UTC | #12

    @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.


    zubair | 2023-10-25 20:13:59 UTC | #13

    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.


    Christopher_Andre | 2023-10-26 19:52:49 UTC | #14

    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?


    zubair | 2023-10-27 00:34:55 UTC | #15

    Christopher_Andre, post:14, topic:22701
    '==' at position 21 : There is no implementation that accepts parameters of String Collection and String
    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

    Christopher_Andre, post:14, topic:22701
    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

    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.


    system | 2023-11-27 00:35:33 UTC | #16

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