Multiple variable from command line

Hi, is possible to call a macro via command line (calling the auto run html page) passing multiple variables? I’ve tried with cmd_var1, cmd_var2, cmd_var3, and all works properly, then calling them into the macro as ${!cmd_var1}, ${!cmd_var2}, ${!cmd_var2}. But my question is: is possible to passing more than 3 variables using the command line call? Also with a different names?

Many thanks & Best regards,
Chris.

Edit 2022: storeEval is deprecated. Now use executeScript_Sandbox to split strings.


I use the Javascript “split” function and storeEval to get an unlimited number of command line variables.

  • You send the values as one long string via cmd_var1=hello%21world***123***it%21works
  • Inside the macro you split the string at *** and assign each part to a separate variable
  • That is all :wink:

Test macro: It splits the string in five parts and assigns it to s1, s2… and s5. Instead of the variable ${s} you would actually use ${!cmd_var1}:

{
  "Name": "split",
  "CreationDate": "2023-3-12",
  "Commands": [
    {
      "Command": "store",
      "Target": "This is parameter1***Hi, I am parameter2***I am No3***I am No4***I am No5",
      "Value": "s",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var str = ${s}; var res = str.split(\"***\"); return res[0]",
      "Value": "s1",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var str = ${s}; var res = str.split(\"***\"); return res[1]",
      "Value": "s2",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var str = ${s}; var res = str.split(\"***\"); return res[2]",
      "Value": "s3",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var str = ${s}; var res = str.split(\"***\"); return res[3]",
      "Value": "s4",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var str = ${s}; var res = str.split(\"***\"); return res[4]",
      "Value": "s5",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Command line var1=${s1}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Command line var2=${s2}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Command line var3=${s3}",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Command line var4=${s4}",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "Command line var5=${s5}",
      "Value": "green",
      "Description": ""
    }
  ]
}

PS: If you have many variable, consider using an array instead of s1…sX

2 Likes

If you have lots of values to import, another good option is to use a CSV file.

WIth the free file access xmodule installed, you can use csvRead to read a csv file directly from the hard drive - you no longer need to import it into the RPA software first.

csvRead | c:\test\data.csv

or simply

csvRead | data.csv (now kantu looks in the default RPA/datasource folder)

=> After csvRead you have the values of the current row ${!col1}, ${!col2},…

You can even set a custom row to read (e. g. 6th row) with store | 6 | !csvReadLineNumber

Really many thanks! It solves my question :slight_smile: