Converting rich ReportMagic output into a flat string
Many ReportMagic macros now return rich object data rather than flat strings.
That makes the output much easier to inspect and work with, but some older patterns still need a flat semicolon-delimited string. When that happens, you can flatten the data with a short nCalc expression.
A common example
Suppose you fetch a list of devices from LogicMonitor:
[LogicMonitor.DeviceList: deviceGroups=Datacenter/Public, =>devices]
That returns a JArray in this kind of format:
[{"Id":123},{"Id":124}]
If you want to pass those device IDs into LogicMonitor.SummaryValueList, you first need to convert that array into a flat string such as 123;124.
The conversion
You can do that with a single nCalc statement:
[=: `join(select(devices,'n','jPath(n,\'Id\')'),';')`, =>deviceIds]
What the expression is doing
select(...) loops through each item in devices.
-
devicesis the input array. -
nis the variable name for each item being evaluated. -
jPath(n,'Id')extracts theIdvalue from each object.
join(...) then combines the selected values into a single string using ; as the separator.
The result is a flat list of IDs that can be passed into macros that expect text input.
Full example
[LogicMonitor.DeviceList: deviceGroups=Datacenter/Public, =>devices]
[=: `join(select(devices,'n','jPath(n,\'Id\')'),';')`, =>deviceIds]
[LogicMonitor.SummaryValueList: deviceIds={deviceIds}, dataPointSpecs=WinCPU^-1^CPUBusyPercent, aggregations=Max, =>MaxCPUList]
Why this matters
This pattern is useful whenever one macro returns structured data but the next macro expects flat text. You can do the conversion inline and keep the report logic in one place.
If you need a different property or a different separator, the same approach still applies. Just change the jPath(...) expression or the delimiter passed into join(...).