Using your example from earlier post ... here is how to set
totalSeconds for use with
exeJavascriptDirect():
(Put the following string in a field and name the field "
jsCode". Then create a global variable in the ToolBook actions system called
tmp.)
var totalSeconds = %1;
totalSeconds %= 3600;
var minutes = Math.floor(totalSeconds / 60);
var seconds = totalSeconds % 60;
if (seconds < 10) {
seconds = "0" + seconds;
}
return minutes + ":" + seconds;
Notice that I have put in a placeholder string (
%1) for the
totalSeconds variable. Since
exeJavascriptDirect() is merely going to execute the above string as a block of JavaScript, all we need to do is grab the string in the actions editor and then replace our placeholders with the logic that is required at runtime. Essentially the above string becomes a boilerplate from which we make substitutions before calling
exeJavascriptDirect().
Notice in the actions below that you must use
pgReplace() to make your string substitutions BEFORE
exeJavascriptDirect() is run.
pgReplace( "%1", [seconds to convert], text of field "jsCode", true, true ); store return value in [tmp]
exeJavascriptDirect( [tmp] ); store return value in [tmp]
Now [
tmp] variable equals "[
minutes]:[
seconds]"
NOTE: exeJavascriptDirect() was not developed to replace creating your own custom functions, but it can be a powerful and dynamic way to execute code on-the-fly in special situations where making a custom js file seems like overkill.