Why can't I get a result from JS to KM variable?

I've done this heaps of times in the past but for whatever reason I am failing to do something really basic here. I've simplified and simplified my macro to the bare minimun and still this is not working.

I am looking to get the value of something (that I have some JS doing on a page) to be passed into a KM variable 'QA _auditor'. In the macro below you can see that I set a value (just so that I can see if it changes), then use JS to pass on that value. The KM variable is empty after running this thugh.

I must be missing something very simple, but am not seeing what's wrong here.

Please help restore my sanity!

1 Like

Note that ultimately the full script will reside in an external js file, this is just done here directly in KM for simplicity to demonstrate the issue.

I'm no expert on JS but according to this

you need to specify return result

2 Likes

:+1:

So, for example:


Or, you can switch off modern syntax,

but then all your KM name:value pairs will still be exported to the global namespace of the browser's JS instance, where other processes can read them.

2 Likes

And, of course, the syntax for referring to KM variable values from JavaScript also differs.

  • The modern syntax defines a local kmvar object in the temporary name-space, whereas
  • the older syntax attaches a kmvar object to the global document object, which persists after the script run.

1 Like

Interesting. I had never noticed those triangles and the options in them, and until now I have never used return varname to send results to a variable, and it's always worked.

I wonder if the default settings for this macro has changed (since update to 11?) which means that this new one isn't working using my old approach (old approach being 'not using return').

Anyway, this info has pointed out a very fine detail that I completely missed. Thanks!

It’s everything to do with KM version 11.

For a bit more info, take a look at this thread:

1 Like