Random function conversion from imacros javascript to ui vision executeScript_Sandbox

@admin @Timo @Plankton @ulrich @thecoder2012

I need help to convert this javascript from imacros to ui vision executeScript_Sandbox

This code randomize 25 elements (letters) and create a 4 characters random value.

Any suggestion to reproduce a similar function in ui vision please ?

SET !VAR3 EVAL("var letters = ['a','b','c','d','e','f','g','h','i','j','k','l',
'm','n','o','p','q','r','s','t','u','w','x','y','z']; 
var string = ''; 
for(var i = 0; i < 4; i++){string += letters[parseInt(Math.random() * 25)]}; 
string")

25 is total elements to randomize (from a to z)
4 is element to obtain after randomization (aaaa or bbbb or akjs)

This works:

What I did was only:

  • Copy the JS code inside executeScript_Sandbox

  • Added a return string; at the end

      {
        "Name": "r1",
        "CreationDate": "2020-1-3",
        "Commands": [
          {
            "Command": "executeScript_Sandbox",
            "Target": "var letters = ['a','b','c','d','e','f','g','h','i','j','k','l', 'm','n','o','p','q','r','s','t','u','w','x','y','z'];  var string = '';  for(var i = 0; i < 4; i++){string += letters[parseInt(Math.random() * 25)]};  return string;",
            "Value": "v1"
          },
          {
            "Command": "echo",
            "Target": "v1=${v1}",
            "Value": "green"
          }
        ]
      }
    

r1

1 Like

Working perfect thanks :slight_smile: