Using an If to check that a string contains a certain substring

Since Ui.Vision Version 8+ you need to use .LastIndexOf of instead of .includes inside executescript_sandbox.

This modified macro works fine:

{
  "Name": "test3",
  "CreationDate": "2023-5-11",
  "Commands": [
    {
      "Command": "store",
      "Target": "test tim meyer",
      "Value": "e",
      "Description": ""
    },
    {
      "Command": "if",
      "Target": "${e}.lastIndexOf(\"tim\") > -1",
      "Value": "",
      "Description": "the return value of .lastIndexOf() is -1 if the substring is not found in the string at all."
    },
    {
      "Command": "echo",
      "Target": "yes, it contains this string",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}
1 Like