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.

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 3 parts and assigns it to s1, s2 and s3. Instead of the variable ${s} you would actually use ${!cmd_var1}:

{
  "Name": "s1",
  "CreationDate": "2018-12-26",
  "Commands": [
    {
      "Command": "store",
      "Target": "hello world***123***it works",
      "Value": "s"
    },
    {
      "Command": "storeEval",
      "Target": "var str = \"${s}\"; var res = str.split(\"***\"); res[0]",
      "Value": "s1"
    },
    {
      "Command": "storeEval",
      "Target": "var str = \"${s}\"; var res = str.split(\"***\"); res[1]",
      "Value": "s2"
    },
    {
      "Command": "storeEval",
      "Target": "var str = \"${s}\"; var res = str.split(\"***\"); res[2]",
      "Value": "s3"
    },
    {
      "Command": "echo",
      "Target": "The new vars are s1=${s1} and s2=${s2} and s3=${s3}",
      "Value": ""
    }
  ]
}
1 Like

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 Kantu first.

csvRead | c:\test\data.csv

or simply

csvRead | data.csv (now kantu looks in the default kantu/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: