Automation Professionals' Integration Toolkit Module

No longer true. :grin:

For Ignition v8.1+: v2.0.3.231942018

With @Matthew.gaitan 's input dataset in a custom property named source, this expression:

forEach(
	asMap(
		groupBy(
			{this.custom.source},
			it()['RouteName'],
			it()['StopName']
		)
	),
	asMap(
		'label', it()[0],
		'expanded', false,
		'data', asMap('nodeType', 'Route'),
		'items', forEach(
			it()[1],
			asMap(
				'label', it()[0],
				'expanded', false,
				'data', asMap('nodeType', 'Stop'),
				'items', forEach(
					it()[1],
					asMap(
						'label', it()['WellName'],
						'expanded', false,
						'data', asMap('nodeType', 'Well'),
						'items', asList()
					)
				)
			)
		)
	)
)

Yields this output:

[
  {
    "label": "Route 1",
    "expanded": true,
    "data": {
      "nodeType": "Route"
    },
    "items": [
      {
        "label": "Stop 1",
        "expanded": false,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 8",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 9",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      },
      {
        "label": "Stop 2",
        "expanded": false,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      }
    ]
  },
  {
    "label": "Route 2",
    "expanded": true,
    "data": {
      "nodeType": "Route"
    },
    "items": [
      {
        "label": "Stop 1",
        "expanded": false,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      },
      {
        "label": "Stop 2",
        "expanded": true,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 8",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      },
      {
        "label": "Stop 3",
        "expanded": false,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 8",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 9",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      },
      {
        "label": "Stop 4",
        "expanded": true,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      }
    ]
  },
  {
    "label": "Route 3",
    "expanded": true,
    "data": {
      "nodeType": "Route"
    },
    "items": [
      {
        "label": "Stop 1",
        "expanded": false,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      },
      {
        "label": "Stop 2",
        "expanded": false,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 8",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 9",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 10",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      },
      {
        "label": "Stop 3",
        "expanded": false,
        "data": {
          "nodeType": "Stop"
        },
        "items": [
          {
            "label": "Well 1",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 2",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 3",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 4",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 5",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 6",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 7",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 8",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          },
          {
            "label": "Well 9",
            "expanded": false,
            "data": {
              "nodeType": "Well"
            },
            "items": []
          }
        ]
      }
    ]
  }
]

The magic is here:

https://www.automation-pros.com/simaids/doc/expression.groupby.html

The asMap() function was altered to handle multi-item keys in a sequence of key-value pairs as requests to make nested mappings. Note that the asMap function will work with key values that are not valid names within Perspective objects, so you may need to construct such maps nested in the expression that consumes them (as in this case).

Both asMap() and asList() were updated to properly return an empty object when given no arguments.

3 Likes