Topics   All   MacOS (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Deprecated   Guides   Examples   Videos
New in version: 9.1   9.2   9.3   9.4   9.5   10.0   10.1   10.2   10.3   10.4    Statistic  

JavaScript.EvaluateScript

Evaluate a string of JavaScript code.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
JavaScriptMac 5.4 Yes No Yes, macOS only No Yes
MBS( "JavaScript.EvaluateScript"; JavaScriptContext; Script { ; URL; startingLineNumber } )   More

Parameters

Parameter Description Example Flags
JavaScriptContext The reference number of the javascript context. $Context
Script The script to evaluate.
URL The source URL for this script.
A URL for the script's source file. Used by debuggers and when reporting exceptions. This parameter is informative only: it does not change the behavior of the script.
Optional
startingLineNumber An integer value specifying the script's starting line number in the file located at sourceURL. This is only used when reporting exceptions. The value is one-based, so the first line is line 1 and invalid values are clamped to 1. 1 Optional

Result

Returns text or error.

Description

Evaluate a string of JavaScript code.

See also WebView.RunJavaScript or WebView.Evaluate for use with web viewer.

Examples

Set variables and use them in the script:

Set Variable [ $js ; Value: MBS( "JavaScript.New" ) ]
Set Variable [ $r ; Value: MBS( "JavaScript.SetProperty"; $js; "FirstName"; "Joe" ) ]
Set Variable [ $r ; Value: MBS( "JavaScript.SetProperty"; $js; "LastName"; "Miller" ) ]
Set Variable [ $r ; Value: MBS( "JavaScript.EvaluateScript"; $js; "FirstName + ' ' + LastName;" ) ]
Show Custom Dialog [ "Result" ; $r ]
Set Variable [ $r ; Value: MBS( "JavaScript.Release"; $js ) ]

Evaluate in javascript the FileMaker get function:

Set Variable [ $js ; Value: MBS( "JavaScript.New" ) ]
Set Variable [ $r ; Value: MBS( "JavaScript.RegisterEvaluateFunction"; $js; "FMEvaluate" ) ]
Set Variable [ $r ; Value: MBS( "JavaScript.EvaluateScript"; $js; "FMEvaluate('Get(AccountName)') + ' from javascript'") ]
Show Custom Dialog [ "Result" ; $r ]
Set Variable [ $r ; Value: MBS( "JavaScript.Release"; $js ) ]

Defines and runs a function in JavaScript:

Let([
f = "
function makeCRCTable(){
        var c;
        var crcTable = [];
        for(var n =0; n < 256; n++){
                c = n;
                for(var k =0; k < 8; k++){
                        c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
                }
                crcTable[n] = c;
        }
        return crcTable;
}

function crc32(str) {
        var crcTable = crcTable || (crcTable = makeCRCTable());
        var crc = 0 ^ (-1);

        for (var i = 0; i < str.length; i++ ) {
                crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
        }

        return (crc ^ (-1)) >>> 0;
};

crc32(InputValue);";
j = MBS( "JavaScript.New" );
r = MBS( "JavaScript.SetProperty"; j; "InputValue"; "Hello World" );
r = MBS( "JavaScript.EvaluateScript"; j; f );
x = MBS( "JavaScript.Release"; j )
];r)

See also

Example Databases

Created 5th November 2015, last changed 9th January 2020


JavaScript.CheckScriptSyntax   -   JavaScript.GetProperty

Feedback: Report problem or ask question.




Links
MBS FileMaker blog