Dear Community,
I am working with automations and currently stumped by a seemingly simple problem that I can find no working solution for. I am building an automation that looks up objects and returns the "fullest" object(s) judging by attributes counted. I will first provide the steps of what I am doing followed by where I run into a problem and what I have already tried:
Object type: MyObjects
> Objects of this type can have a varying number of entries contained in their attributes. The main assumption is: "The more attribute entries an object contains, the more relevant it becomes as a query result".
MyObject Attributes:
- Key (must be filled and limited to 1 entry, must be unique)
- Name (must be filled and limited to 1 entry, must be unique)
- A1 (can be empty, can have multiple entries)
- A2 (can be empty, can have max. 1 entry)
- [...]
Query: Some Query that returns multiple objects from type MyObjects.
Output: {{LookupObjects}} with SmartObjects represented by tag. For example "KEY-1, KEY-4, [...], KEY-12"
> List of Asset-Objects matching some search criteria gets filled into {{LookupObjects}}
Smart Value: {{#lookupObjects.attributes}}{{size.asNumber}},{{/}}
> count of "how mighty" each object is (how many filled attributes it contains). Output e.g. "12,13,12,10,12,[...],12,"
Smart Value: {{CountFilledAttributes.split(",").max}}
> Returns the maximum Number from the previous list. Output e.g. "13"
Smart Value: {{#lookupObjects}}{{#if(equals(attributes.size.asNumber, $AttributeCountMax.asNumber))}}{{.}}, {{/}}~{{/}}
> Should make a list containing only objects that have the priviously found maximum number of attributes. "~" is contained for Debug porpuses, will be dropped in final iteration
Objects initially found: {{LookupObjects}} || Attribute Counts: {{CountFilledAttributes}} || Max Count: {{AttributeCountMax}} || Objects with Max Count: {{ObjectsWithMaxCount}}
For this example: {{ObjectsWithMaxCount}} does not work properly and returns only "~~~~[...]~"
In general: How do i get the smart object to use my smar variable {{AttributeCountMax}} while iterating over the listed items from {{LookupObjects}}? I know that there are threads close to this subject but I can't find any tackling this specific subject.
I am aware and confident that I could restructure this to run and work using custom branching and I will do so if actually necessary - even if it feels a bit inelegant (I strongly suspect it will result in quite a bit of additional runtime). I still pose this question as I would love to deepen my understanding about automation function behaviour here, please bear with me (and let me extend a big thanks at everyone helping me here).
> returns the expected result. e.g. "~KEY-4,~~[...]~
> returns incorrect result. e.g. "~~~[...]~". Kind of expected because "AttributeCountMax" obviously does not exist as an Attribute on the asset objects so NULL would be returned, making the equals logic false on every comparison. (I checked if it would return all items if I would change attributes.size.asNumber into something that returns NULL and sure enough: All items from the list DID get returned.)
> (expectedly) doesn't render. Automation hates nested curvy brackets
> doesn't render, $ doesn't seem make nested curvy brackets more palatable to our poor little automation.
> doesn't render, automation also seems to hate random brackets
> returns incorrect result. e.g. "~~~[...]~"
> returns incorrect result. e.g. "~~~[...]~"
> returns incorrect result. e.g. "~~~[...]~". At this point i am running out of ideas and I am gennerally unsure if the $ even does anything.
I feel like i am missing just one syntax detail and I will be greatly thankful for any suggention and educational content on this matter.
Kind regards,
Ludwig
EDIT: fixed some typos