Hey all, I am using the HTTP action to get the device status, works great! I would like to show the list of devices in rows, vs. just a list separated by commas.
I think I can use - join(items, “\r\n”)
however, I am not sure how to get it working with this -
join(map(filteredItems, item.name), ", ")
I tried - join(map(filteredItems, item.name, “\r\n”), ", ")
No luck. Any help is greatly appreciated!
I recently ask a similar question, from how I understand it, join(map(filteredItems, item.name), ", ") already has join method included, so swapping it out for new line, join(map(filteredItems, item.name), “\r\n”) should sort it
It looks like @Paul_Paul has you pointed in the right direction.
You had the right idea with your attempt, but the syntax was off a bit. With the nested functions like that, sometimes it’s easier to break them up into their own line by assigning the result of each function call to a expression-local variable:
So we could split up the original into the following format:
Then it makes it easier to know where to tweak things. In your case, it sounds like you want to use newline characters instead of comma separating things. So you would swap out the ", " for "\r\n":
Also keep in mind that if you are using sample data and testing your expression manually in the expression editor that the result preview will not show the new lines. Similarly, if you view the variable value in the list of variables, you won’t see the new lines there.
But the new lines will show up when used in a Variable Tile or within a notification like an email.
I can’t think of a great way to do that off the top of my head.
Can you share more details about what you are trying to accomplish? Are you trying to get the array of ‘names’ and then sort that list alphabetically?
Or are you trying to sort things while it’s still a list of objects with other properties that you might be interested in sorting on before outputting just the name?
Can you share more details on what you are trying to accomplish and what you’ve tried?
There’s some examples in the original Health and Battery Reports thread that’s a good starting point:
When in doubt, I would also recommend reading the expressions documentation, especially the linked General Functions reference:
As you’ll note from the original example, the filter(array, expression) filters to items that return true for the expression. So to do the original exclusion example linked above, we are adding a not() to invert things… so an inclusion is basically the same thing without a not()