Question to get all user defined tags for blockly script

Hi folk,
for a Retention script I need a list / dictionary of all user defined tags of all existing items. The API give only sementic tags from default setup.

How can I get a list, without I iterate through all items an read the properties element “tags”?

You can’t. The only way I know is to iterate through all the Items. Unfortunately this sort of thing is awkward in Blockly so it might be worth using an inline script block.

var allTags = items.getAllItems().map( i => new Set(i.tags) ).reduce( (accumulator, value) => accumulator.union(value) );

This uses the mapto get the list of tags for each Item and convert the Array to a Set. The reduce uses the union operator to merge all the Sets into one Set. Because it’s a Set, each tag will only be listed once.

To do this in Blockly, you’ll have to iterate over all the Items and then over all the tags of each Item and add them to a List one by one if the tag isn’t already included. In JS Scripting the code for that would look something like:

var allTags = [];
items.getAllItems().forEach( i => {
  i.tags.forEach(t => {
    if(!allTags.includes(t)) allTags.push(t);
  });
});

Hi,
I get this error
Script execution of rule with UID 'ca832b5e94' failed: org.graalvm.polyglot.PolyglotException: TypeError: (intermediate value).getAllItems is not a function

Can you help me, whats wrong…
image

My mistake. It’s just getItems

items.getItems().forEach( i => {