0

I'm working on a power automate flow and I'm having some trouble. I copied some text to my clipboard in the flow and i asigned it to a variable in my flow. I'm trying to parse the variable using the javascript scripting feature but i'm getting a syntax error whenever I try to use the %variable% syntax in javascript. I used the variable button in the text editor they give you to add the variable to my script but even something simple as var res = %SimResults%; returns an error C:\Users\$me\AppData\Local\Temp\Robin\nkwrgcdoxrp.tmp(1, 11) Microsoft JScript compilation error: Syntax error

It seems that even though I Should be able to access my flow variables from Javascript it throws a syntax error when I try

Brandon Piña
  • 614
  • 1
  • 6
  • 20

1 Answers1

1

You'll need to put quotes around it ...

var res = "%SimResults%"

... it treats the variables as more of a find and replace within your Javascript code, therefore, you need to do the work to ensure the correct encapsulation, etc. exists.

This may not solve your problem though depending on the complexity of what is contained within the variable.

If you have additional quotes, etc. you may need to escape them prior to putting them in the Javascript task IF they exist within the string ... just be mindful of that.

Skin
  • 9,085
  • 2
  • 13
  • 29
  • 1
    Wow, I absolutely hate that. Especially since Jscript is based off of ES5 which doesn't support multiline strings. Also for some reason i can't get console.log to work??? I've switched to python and using triple quotes for multiline strings works like a charm. Also the print() function works properly – Brandon Piña Feb 23 '22 at 17:12
  • As crazy as it sounds, I’ve been known to use Excel for more advanced scripting tasks because I can load it into a cell first and then VBA is none the wiser. It adds a dependency to a workbook with the relevant VBA though which can be a drawback. PowerShell scripts have the same problem. – Skin Feb 23 '22 at 20:13