I'm wondering how to use a substring of a layer name as a condition for an if/else expression.
I want to verify that the layer above the layer with the expression, has a specific (part of a) name, and if so, it executes some code.
I have added an example. In the example it is only a single word, but I want to be able to apply it to for example "Text Column 1" in such a way that the code will be executed if "Text Column" is in the layer name.
I hope my question is clear and that there is someone who can help me.
Thanks in advance
Copy link to clipboard
I think your attempt
name.substr(...) = "Heading"
has two problems:
1) you need to use == instead of =
2) the second parameter of substr() is the length of the substring you want to get.
So to compare it to "Heading" which has 7 letters, you should do substr(0,7).
Extra tip: If you don't want to find it only at the beginning of the comp name, use the function indexOf:
// name contains "Heading"
You should run the script in the debugger and see at which line the error occurs exactly. Without a line number, this error message is not helpful.