Skip to content

Array mapping resolver name

Tracy Li edited this page Jun 4, 2018 · 1 revision

Representative array mapping and trigger mapping

Array Resolver

Today we using $. for trigger mapping(means current scope) and array mapping(to get current context value)

It has an issue when doing an array mapping in trigger mapping, it doesn't know it from a trigger or current array context.

Upon we discussed on Friday(June 1), we will continue to use $. for trigger mapping but need to find another way for array mapping Take an example doing an array mapping inside a rest trigger.

{
    "mappings": {
        "input": [
            {
                "mapTo": "flowInputLevel1",
                "type": "array",
                "value": {
                    "fields": [
                        {
                            "from": "$.id1",
                            "to": "$$['id1']",
                            "type": "primitive"
                        },
                        {
                            "fields": [
                                {
                                    "from": "$.id2",
                                    "to": "$$['id2']",
                                    "type": "primitive"
                                },
                                {
                                    "from": "$.name2",
                                    "to": "$$['name2']",
                                    "type": "primitive"
                                }
                            ],
                            "from": "$.triggerOutputLevel2",
                            "to": "$$['flowInputLevel2']",
                            "type": "foreach"
                        },
                        {
                            "from": "$.name1",
                            "to": "$$['name1']",
                            "type": "primitive"
                        }
                    ],
                    "from": "$.body.triggerOutputLevel1",
                    "to": "flowInputLevel1",
                    "type": "foreach"
                }
            },
            {
                "mapTo": "flowRootField",
                "type": "expression",
                "value": "$.body.rootField"
            }
        ]
}
  1. Straight mapping trigger root field($.body.rootField) to flowRootField. $.body means get currect tirgger attribute body.
  2. Another mapping is an array mapping structure. Map trigger output $.body.triggerOutputLevel1 to flowInputLevel1, both are JSON array. foreach trigger outputLevel1 and assigin it's id1 and name1 to flow flowInputLevel1 field id1 and name1, same with second level.

For both 1 and 2 mapping are using $. the prefix which confuses. #1 using $. to get current data scope data but #2 using for current array context.

Several approaches.

  • $element
  • $current --> Today the iterator feature already token $current
  • $array
  • $iterator --> $Iterator more like foreach or loop, the resolver should just for currect loop context.
  • more.....

Accessing array parent data

Assume we have 2 level array, how to access first level data from second level? Some approaches

  • $current["FlowinputLevel1"].id
  • $current["arrayinputLevel1.arrayInputLevel2"].id