Another v.7 JS problem. while_v2 can't do a simple comparison now?

What is wrong with this that’s throwing an Unexpected token error?

{ "Command": "while_v2", "Target": "${currentClaimNumber} == \"#nomatchfound\"", "Value": "", "Description": "" },

I’m stuck @admin

This v7 change has really screwed me and my workflow, but as I go to update hundreds of sandbox entries to non-sandbox, things like the above are really problematic because there’s no explanation or workaround. There’s no ES5 vs 6 reason that I can see for == to suddenly not work.

The issue here appears to be the #, but why? If I remove that, the error goes away but, obviously, that solves nothing since that’s what I need to test for!

Ok, so it has nothing to do with the #… its just if the condition is TRUE then I get thie “unexpected token” error.

That makes even less sense.

For me ${currentClaimNumber} == \"#nomatchfound\" works fine in 7.0.11, here is my test macro:

{
  "Name": "test JS",
  "CreationDate": "2022-5-13",
  "Commands": [
    {
      "Command": "store",
      "Target": "hello",
      "Value": "currentClaimNumber",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "#nomatchfound",
      "Value": "currentClaimNumber",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "${currentClaimNumber} == \"#nomatchfound\"",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "inside IF",
      "Value": "green",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "while_v2",
      "Target": "${currentClaimNumber} == \"#nomatchfound\"",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "inside WHILE",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "throwError",
      "Target": "all ok, just stopping inside while",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

PS: You can test your JS code here:

https://neil.fraser.name/software/JS-Interpreter/

This is the JS interpreter we are using now for executeScript_Sandbox and IF/WHILE/etc

Notepad++ did a great job to do my 530 non-sandbox text changed in my tons of .json macro files.

1 Like

I suppose we’re supposed to ignore all the reasons they gave to not use non-sandbox unless absolutely necessary.

It also doesn’t help for the if_v2 or while_v2, which use sandbox.

@bcsteeve Can you confirm that the original issue is actually solved? Or do you still see the issue? If so, a complete, small test macro would be good.

I suppose we’re supposed to ignore all the reasons they gave to not use non-sandbox unless absolutely necessary.

Well, yes, you are right: Now I would recommend to use executeScript as default.

For if/while we continue to use the sandbox version because usually inside a “if” you have only basic Javascript, and ES5 is fine for that. And it would be hard to explain that a web page has to be open just to use “if”.

That’s an interesting statement and makes sense. However why did the “if” statement then still lost the “.starwith()” javascript functionality if it still runs in the sandbox?

@noahhath StartsWith is an ES6 feature, but instead you can use lastIndexOf. For details please see my answer here String search ".startsWith" and ".includes"