0

Given an array shown below

array:

{
        "documentToSigner": [
          {
            "documentName": "ESRA For aa aa",
            "typeCd": "SIGNATURE",
            "subtypeCd": "CAPTURE",
            "eSignLiveExtension": {
              "extractInd": true
            },
            "documentItemName": "Signature001"
          },
          {
            "documentName": "ODP Agreement",
            "typeCd": "SIGNATURE",
            "subtypeCd": "CAPTURE",
            "eSignLiveExtension": {
              "extractInd": true
            },
            "documentItemName": "Signature002"
          },
          {
            "documentName": "ODP Agreement",
            "typeCd": "INPUT",
            "subtypeCd": "LABEL",
            "eSignLiveExtension": {
              "extractInd": true,
              "autoFieldBindingCd": "{approval.signed}"
            },
            "documentItemName": "SignatureDate002"
          }
        ]
      }

I have an JSON variable as below I want to filter and extract the noOfDocumentItemToSigner if the key and content version from Array matches with the JSON.

Example: For: aAuDQ0000004mX60AI contentVersion: 068DQ000000lK0iYAE

Expected output:

{ "documentName": "ESRA For cc cc", "documentItemToSigner": [ { "typeCd": "SIGNATURE", "subtypeCd": "CAPTURE", "eSignLiveExtension": { "extractInd": true }, "documentItemName": "Signature001" } ] }, { "documentName": "ODP Agreement", "documentItemToSigner": [ { "typeCd": "SIGNATURE", "subtypeCd": "CAPTURE", "eSignLiveExtension": { "extractInd": true }, "documentItemName": "Signature004" }, { "typeCd": "INPUT", "subtypeCd": "LABEL", "eSignLiveExtension": { "extractInd": true, "autoFieldBindingCd": "{approval.signed}" }, "documentItemName": "SignatureDate004" } ] }

2
  • Add expected result vs actual result to the question. Commented Nov 30, 2024 at 16:16
  • @aled I have updated the question with proper Inputs and expected output Commented Dec 4, 2024 at 16:46

4 Answers 4

0

You can get an array of all the available content versions either using "Descendants" selector like below

var requiredVersions = vars.inputJson..contentVersion

It is an easy way but I have experienced performance impact with the above method. If your input is large and the performance impact is significant, you can use a combination of valuesOf to get the array of all versions

var requiredVersions = flatten(valuesOf(vars.inputJson))

After this you can filter the required versions from payload

%dw 2.0
output application/json
var requiredVersions = flatten(valuesOf(vars.inputJson)).contentVersion
---
payload filter ((item, index) -> 
    requiredVersions contains item.contentVersion) 
map ((item, index) -> {
    // do the mapping here
})
Sign up to request clarification or add additional context in comments.

1 Comment

I have updated the question with proper input and expected output
0

If I understand your problem statement correctly, you just need to extract noOfDocumentItemToSigner based on contentVersion which is coming in array.

You can use selector functions in combination with map to extract the values.

%dw 2.0
output application/json
var listOfContentVersions=["068DQ000000lK0iYAE","068DQ000000lK0OYAU"]
---
listOfContentVersions map(v,i)-> {(v):payload[?($.contentVersion==v)][0].noOfDocumentItemToSigner map { 
    // mapping here
}}

1 Comment

I have updated the question with proper input and expected output
0

if I understood your question correctly (in regards what is in the payload and what is in the input array) I was able to write this mapping, to be able to find matches between those two data sets:

%dw 2.0
output application/json

var myPayload = {
  "aAuDQ0000004mX60AI": [
    {
      "noOfDocumentItemToSigner": ["eSign_documentItemName1__c"],
      "contentVersion": "068DQ000000lK0iYAE",
      "documentName": "ESRA with Exhibit_A"
    },
    {
      "noOfDocumentItemToSigner": ["eSign_documentItemName1__c"],
      "contentVersion": "068DQ000000lK0OYAU",
      "documentName": "ODP Agreement"
    }
  ],
  "aAuDQ0000004mXG0AY": [
    {
      "noOfDocumentItemToSigner": ["eSign_documentItemName1__c"],
      "contentVersion": "068DQ000000lK0JYAU",
      "documentName": "ESRA For bb bb"
    },
    {
      "noOfDocumentItemToSigner": ["eSign_documentItemName1__c", "eSign_documentItemName2__c"],
      "contentVersion": "068DQ000000lK0OYAU",
      "documentName": "ODP Agreement"
    }
  ]
}

var myInputArray = [
    {
        "noOfDocumentItemToSigner": [
        "eSign_documentItemName1__c",
            "eSign_documentItemName2__c"
        ],
        "contentVersion": "068DQ000000lK0iYAE",
        "documentName": "ESRA with Exhibit_A"
    },
    {
        "noOfDocumentItemToSigner": [
        "eSign_documentItemName1__c"
        ],
        "contentVersion": "068DQ000000lK0OYAU",
        "documentName": "ODP Agreement"
    }
]

---
myPayload mapObject ((value, key, index) -> {
    (key): (value) map ((item, index) -> {
        noOfDocumentItemToSigner: item.noOfDocumentItemToSigner,
        contentVersion: item.contentVersion,
        documentName: item.documentName
    }) filter $.contentVersion == (myInputArray map ((item2, index2) -> item2.contentVersion))[index]
})

Comments

0
 %dw 2.0
    output application/json
    var input = {
  "individualToEvent": [
    {
      "documentToSigner": [
        {
          "documentName": "ESRA For aa aa",
          "typeCd": "SIGNATURE",
          "subtypeCd": "CAPTURE",
          "eSignLiveExtension": {
            "extractInd": true
          },
          "documentItemName": "Signature001"
        },
        {
          "documentName": "ODP Agreement",
          "typeCd": "SIGNATURE",
          "subtypeCd": "CAPTURE",
          "eSignLiveExtension": {
            "extractInd": true
          },
          "documentItemName": "Signature002"
        },
        {
          "documentName": "ODP Agreement",
          "typeCd": "INPUT",
          "subtypeCd": "LABEL",
          "eSignLiveExtension": {
            "extractInd": true,
            "autoFieldBindingCd": "{approval.signed}"
          },
          "documentItemName": "SignatureDate002"
        }
      ]
    }
  ]
}

var output =  "documentToSigner": [
          {
            "documentName": "ESRA For cc cc",
            "documentItemToSigner": [
              {
                "typeCd": "SIGNATURE",
                "subtypeCd": "CAPTURE",
                "eSignLiveExtension": {
                  "extractInd": true
                },
                "documentItemName": "Signature001"
              }
            ]
          },
          {
            "documentName": "ODP Agreement",
            "documentItemToSigner": [
              {
                "typeCd": "SIGNATURE",
                "subtypeCd": "CAPTURE",
                "eSignLiveExtension": {
                  "extractInd": true
                },
                "documentItemName": "Signature004"
              },
              {
                "typeCd": "INPUT",
                "subtypeCd": "LABEL",
                "eSignLiveExtension": {
                  "extractInd": true,
                  "autoFieldBindingCd": "{approval.signed}"
                },
                "documentItemName": "SignatureDate004"
              }
            ]
          }
        ]
---
input.documentToSigner 
  // Group items by documentName
  groupBy ((item) -> item.documentName) 
  // Transform each group to have documentName and documentItemToSigner
  mapObject ((documentName, items) -> {
    documentName: documentName,
    documentItemToSigner: items map ((item) -> 
      item - 'documentName' // Remove documentName from each item
    )
  })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.