My stored text is working fine. I can use an IF/Elseif with the ${txt}.includes("test") but want to include more terms

Hi everyone - I really hope someone can help. Appreciate your time.

Currently.
The target is: ${Result}.includes(“3 months”)

I want to know several things

  1. How do I write the target for multiple ‘or’ i.e “3 months” or “5 months” or “1 year”
  2. How do i write the target for ‘does not contain’ “3 months”
  3. How do I write the target for contains “3 months” but ‘does not contain’ “5 months”

I have searched the documentation but can not find these answer.

This is more of a Javascript version than RPA software. You can use all Javascript operators inside the IF clause!

So the answer to your question #3 is:

${a}.includes("3 months") && !${a}.includes("5 months")

Test macro (See also includes):

{
  "Name": "if OR",
  "CreationDate": "2021-6-16",
  "Commands": [
    {
      "Command": "store",
      "Target": "3 months 5 months one year",
      "Value": "a",
      "Description": ""
    },
    {
      "Command": "comment",
      "Target": "if_v2 // (${a}.includes(\"3 months\") == true) && (${a}.includes(\"5 months\") == false)",
      "Value": "",
      "Description": "longer version with == true"
    },
    {
      "Command": "if_v2",
      "Target": "${a}.includes(\"3 months\") && !${a}.includes(\"5 months\")",
      "Value": "",
      "Description": "short version with ! operator"
    },
    {
      "Command": "echo",
      "Target": "found!",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "else",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "NOT found!",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

Great - awesome thanks for taking the time to solve for me !

In the new Ui.Vision versions the above macro returns " undefined is not a function" because since Ui.Vision Version 8+ you need to use .LastIndexOf of instead of .includes inside executescript_sandbox.

This modified macro works fine:

{
  "Name": "lastIndexOf",
  "CreationDate": "2023-5-11",
  "Commands": [
    {
      "Command": "store",
      "Target": "3 months 5 months one year",
      "Value": "a",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "3 months 11 months one year",
      "Value": "a",
      "Description": ""
    },
    {
      "Command": "if",
      "Target": "${a}.lastIndexOf(\"3 months\") > -1 && ${a}.lastIndexOf(\"5 months\") == -1",
      "Value": "",
      "Description": "short version with ! operator"
    },
    {
      "Command": "echo",
      "Target": "string contains “3 months” but ‘does not contain’ “5 months”",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "else",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "NOT found!",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}