Compare Ids in PARENT and Collection

I currently have an export with a similar structure to below:

{
  "record": {
    "ParentId": "ParentId",
    "IsDeleted": "IsDeleted",
    "Name": "Name",
    "Collection": [
      {
        "CollectionId": "CollectionId",
        "CollectionName": "CollectionName"
      },
      {
        "CollectionId": "CollectionId",
        "CollectionName": "CollectionName"
      }
    ]
  }
}

Where 'record' is the parent object exported and collection are the related records associated with the parent.

I want to loop through the Ids in the collection and compare them to the Id in the Parent. I have wrote this handlebar to do this:

{{#each Collection}}{{#compare CollectionId "===" record.ParentId}}{{Name}}{{else}}Default Value{{/compare}}{{/each}}

I have tried record.Id and _PARENT.Id to access the value in the parent but the handlebar simply defaults to the default else statement.

Is it possible to access the values outside of a collection when using the #each helper? And if so, how can I do so? 

0

Comments

4 comments
Date Votes
  • Hey David O'Neill,

    This would be the great time I would leverage the Celigo AI helper for us to write the handlebar.

    You just need to give the prompt to Celigo AI in way you want and you'll get the outcome.
    Below I have pasted the handlebar. I hope this helped you.

    {{#each record.Collection}}
      {{#compare CollectionId "==" ../record.ParentId}}
        {{../record.Name}}
      {{else}}
        defaultvalue
      {{/compare}}
    {{/each}}

    Regards, 
    Lakhan B

    1
  • Hi Lakhan

    Thanks for the quick reply. The handlebar suggested does not work unfortunately.

    Can you tell me how to access Celigo AI for the handlebars? The only AI options I seem to have are on the mapping screen and when edit scripts.

    Thank you

    David

    0
  • David O'Neill what output are you trying to get? Are you trying to get the parent level Name into the collection that matches or bring the collectionname up to the parent level?

    0
  • Excuse me folks, my mistake. I simplified the data structure to make it easier to understand the suggestion by Lakhan and when I edited it to match the real structure it worked like a charm.

    Thank you all.

    0

Please sign in to leave a comment.

 

Didn't find what you were looking for?

New post