Hi,
getting no results after hours with my own library using more than one line.
Following is working:
uid: blocklibrary_isTagged
tags: []
props:
parameters: []
parameterGroups: []
timestamp: Apr 2, 2024, 2:30:26 PM
component: BlockLibrary
config:
name: Contains Tag(s)
slots:
blocks:
- component: BlockType
config:
type: contains_tag
message0: Item %1 contains tag %2 ?
args0:
- type: input_value
name: sourceItem
check: oh_item
- type: input_value
name: TAG
check: String
output: Boolean
colour: 190
tooltip: Check if the list contains the specified string.
helpUrl: ""
slots:
toolbox:
- component: PresetInput
config:
name: sourceItem
shadow: true
type: oh_item
- component: PresetInput
config:
name: TAG
shadow: true
type: text
fields:
TEXT: tag
code:
- component: BlockCodeTemplate
config:
template: items.getItem({{input:sourceItem}}).tags.includes({{input:TAG}})
utilities:
- component: UtilityJavaType
config:
javaClass: org.openhab.core.model.script.actions.Things
name: things
But now I want to look for an array as second argument, leeds me for at least one loop and multiple lines:
code:
- component: BlockCodeTemplate
config:
template: >
var sourceItem = '{{input:sourceItem}}';
var tags = '{{input:TAGS}}';
var itemData = items[sourceItem];
var itemTags = itemData.tags.split(',');
var result = true; tags.forEach(function(tag) {
if (!itemTags.includes(tag)) {
result = false;
return;
}
}); return [result];
That could never work…
console.error((var sourceItem = ''ZWave_Node_042_Fenster''; var tags = ''; var itemData = items[sourceItem]; var itemTags = itemData.tags.split(','); var result = true; tags.forEach(function(tag) {
if (!itemTags.includes(tag)) {
result = false;
return;
}
}); return [result];
));
How does design work here?