Conversion split function from storeEval to executeScript_Sandbox

Hi

I need to convert split function from storeEval to executeScript_Sandbox

COL 1 Value = Cat-Dog
First_Value = Cat
Second_Value = Dog
Separator = -

This is my old code deprecated, I need to adapt it to the executeScript_Sandbox

Thanks

{
  "Command": "storeEval",
  "Target": "\"${!COL1}\".split(\"-\")[${0}].trim();",
  "Value": "First_Value"
},
{
  "Command": "storeEval",
  "Target": "\"${!COL1}\".split(\"-\")[${1}].trim();",
  "Value": "Second_Value"
}

May be this works for you.
The value in the column 1 of the csv-filee is in this example <1025102025> (only the number).

{
  "Command": "store",
  "Target": "${!col1}",
  "Value": "var_value_01"
},
{
  "Command": "storeEval",
  "Target": "\"${!COL1}\".split(\"2\")[0].trim();",
  "Value": "1rst_Value"
},
{
  "Command": "echo",
  "Target": "${1rst_Value}",
  "Value": ""
},
{
  "Command": "storeEval",
  "Target": "\"${var_value_01}\".split(\"2\")[0].trim();",
  "Value": "1rst_Value_var"
},
{
  "Command": "echo",
  "Target": "${1rst_Value_var}",
  "Value": ""
},
{
  "Command": "executeScript_Sandbox",
  "Target": "return ${var_value_01}.split(\"2\")[0].trim()",
  "Value": "1rst_Value_var_new"
},
{
  "Command": "echo",
  "Target": "${1rst_Value_var_new}",
  "Value": ""
},
{
  "Command": "executeScript",
  "Target": "return ${var_value_01}.split(\"2\")[1].trim()",
  "Value": "2nd_Value"
},
{
  "Command": "echo",
  "Target": "${2nd_Value}",
  "Value": ""
}
1 Like

Hi

Thanks for your suggestion, i think the storeeval will be removed because in the new version of kantu will be renamed with deprecated, and will not be supported in future.

I think executeScript_Sandbox is the only command to use because storeEval is deprecated and soon with not supported.

The is only listed to make it possible to compare the different Options.
And it Shows that the code example from the original post contains an error:
<… ")[{0}]....> Using <{0}> instead <[0]> is throwing an error.
Sorry for the missing explanation to this points

I solved with your code this is the complete code

> {
>   "Name": "Split Function",
>   "CreationDate": "2019-9-11",
>   "Commands": [
>     {
>       "Command": "store",
>       "Target": "11111-22222",
>       "Value": "Col"
>     },
>     {
>       "Command": "executeScript_Sandbox",
>       "Target": "return ${Col}.split(\"-\")[0].trim()",
>       "Value": "First_Part"
>     },
>     {
>       "Command": "echo",
>       "Target": "${First_Part}",
>       "Value": ""
>     },
>     {
>       "Command": "executeScript_Sandbox",
>       "Target": "return ${Col}.split(\"-\")[1].trim()",
>       "Value": "Second_Part"
>     },
>     {
>       "Command": "echo",
>       "Target": "${Second_Part}",
>       "Value": ""
>     }
>   ]
> }


[status]

Playing macro Split Function

[info]

Executing:  | store | 11111-22222 | Col | 

[info]

Executing:  | executeScript_Sandbox | return ${Col}.split("-")[0].trim() | First_Part | 

[info]

Executing:  | echo | ${First_Part} |  | 

[echo]

11111

[info]

Executing:  | executeScript_Sandbox | return ${Col}.split("-")[1].trim() | Second_Part | 

[info]

Executing:  | echo | ${Second_Part} |  | 

[echo]

22222

[info]

Macro completed (Runtime 2.17s)
1 Like

I convert my variable into array and then access the array values

{
“Name”: “testForArray”,
“CreationDate”: “2019-9-11”,
“Commands”: [

{
  "Command": "store",
  "Target": "Mon,Tue,Wed,Thu,Fri,Sat,Sun",
  "Value": "varString"
},
{
  "Command": "executeScript_Sandbox",
  "Target": "return ${varString}.split(\",\")",
  "Value": "varArray"
},
{
  "Command": "executeScript_Sandbox",
  "Target": "return ${varArray}.length",
  "Value": "varLength"
},
{
  "Command": "executeScript_Sandbox",
  "Target": "return ${varArray}[0]",
  "Value": "varSingleVal"
},
{
  "Command": "echo",
  "Target": "String: ${varString}",
  "Value": ""
},
{
  "Command": "echo",
  "Target": "Array: ${varArray}",
  "Value": ""
},
{
  "Command": "echo",
  "Target": "${varLength}",
  "Value": ""
},
{
  "Command": "echo",
  "Target": "${varSingleVal}",
  "Value": ""
}

]
}

1 Like

Working like a charm, many thanks for your solution.

is this answer depreciated? its not working for me