Remove blanksteps from storeText

Hello! I’m new to UI.Vision and to coding in general. I have searched quite extensively but can’t get it right so I guess I’m making some n00b mistake here.

I try to store the text “1 200” from a cell, remove the blankstep, and then type it as “-1200” into a text box. Everything is working very well except removing the blank step. The code looks like this at the moment. I guess the error is within the executeScript-part? But I’ve copied it from one of the demo-macros.

“Command”: “storeText”,
“Target”: “xpath=//*[@id=“premierAvd2”]/tbody/tr[2]/td[5]”,
“Value”: “val1”
},
{
“Command”: “executeScript”,
“Target”: “return ${val1}.replace(/( |\n|\r)/gm, “”)”,
“Value”: “”
},

{
  "Command": "type",
  "Target": "id=Berakningsunderlag",
  "Value": "-${val1}",
},

Here the solution with a special javascript to take number only

{
  "Name": "Take Numbers",
  "CreationDate": "2021-2-25",
  "Commands": [
    {
      "Command": "store",
      "Target": "1 200",
      "Value": "Var"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var mystring = ${Var}; var replaced = mystring.replace(/\\D/g, ''); return replaced",
      "Value": "Var"
    },
    {
      "Command": "echo",
      "Target": "-${Var}",
      "Value": "#shownotification"
    }
  ]
}

Result

  • [status]

Playing macro Take Numbers

  • [info]

Executing: | store | 1 200 | Var |

  • [info]

Executing: | executeScript_Sandbox | var mystring = ${Var}; var replaced = mystring.replace(/\D/g, ‘’); return replaced | Var |

  • [info]

Executing: | echo | -${Var} | #shownotification |

  • [echo]

-1200

  • [info]

Macro completed (Runtime 1.07s)

2 Likes

Tanks a lot, works like a charm!

1 Like