Saving return value in variable stuck

Attached macro JS_Function.kmmacros (5.2 KB)

When I run the javascript script in console all works fine, and even at runtime in the console it shows the correct return. However everytime the keyboard alert action runs it's empty it doesn't save the variable.

In my js function I basically say if X is there return A, if Y is there return B - all works well and should be saving whichever is returned as the resulting variable but unfortunately not

Even if the KM macro is properly triggered, your JavaScript will not run -- it only DEFINES a function. It does NOT run it.
To run a function, you have to use this form:

Auto-execute JavaScript function

//--- The function must be wrapped in parenthesis () ---
(function myMain() {      // this will auto-run when script is executed

var kmVar = document.kmvar.VARNAME;
var scriptResults = "TBD"

//--- YOUR CODE HERE ---

return scriptResults;
}  // END of function myMain()

//---- Closing parenthesis, and then another pair to execute the function ---
)();

You're the best! thanks

1 Like