fm-gofer
TypeScript icon, indicating that this package has built-in type declarations

1.7.1 • Public • Published

fm-gofer

Promises in FM Web Viewers!

It's like fetch() for FileMaker! Go'fer some data. Call FileMaker scripts from JavaScript in a web viewer and get the response back using async/await.

Try it

Check out ./example/FMGofer.fmp12. This example demostrates the callback, resolve, reject, and timeout capabilities of the library. You can rebuild the example code used in the fm file by running npm run build && npm run build:example. This will output an html file in example/dist/index.html, which can be used in a FM webviewer.

Install fm-gofer in your JS project

npm install --save fm-gofer

Usage

Import fm-gofer

import syntax:

import FMGofer from 'fm-gofer';

require syntax:

const FMGofer = require('fm-gofer');

Or import from a CDN for convenience:

<!-- This will set a global window property FMGofer -->
<script src="https://unpkg.com/fm-gofer/dist/fm-gofer.umd.cjs"></script>

Or copy into yout HTML for offline apps:

<script>
  // This will set a global window property FMGofer
  (copy of ./dist/fm-gofer.umd.cjs)
</script>

Use fm-gofer

In your JS:

var a = await FMGofer.PerformScript('FM Script', param);
var b = await FMGofer.PerformScriptWithOption('FM Script', param, 5);

// Set a custom timeout/timeout message if the default to wait indefinitely is too long
var c = await FMGofer.PerformScript('FM Script', param, 5000, 'timed out!');
var d = await FMGofer.PerformScriptWithOption(
  'FM Script',
  param,
  5,
  5000,
  'timed out!'
);
// or set the timeout to zero to wait forever
var c = await FMGofer.PerformScript('FM Script', param, 0);

In your FileMaker script:

To return data to JS, extract callbackName and promiseID from Get ( ScriptParameter ), and use it to call back to JS and resolve/reject the promise. Pass True as the last param ("failed") to reject the promise.

Set Variable [ $callbackName ; JSONGetElement ( Get(ScriptParameter) ; "callbackName" ) ]
Set Variable [ $promiseID ; JSONGetElement ( Get(ScriptParameter) ; "promiseID" ) ]
# this contains param data sent from JS
Set Variable [ $parameter ; JSONGetElement ( Get(ScriptParameter) ; "parameter" ) ]

# callback to JS like: $callbackName($promiseID, <dataToReturn>, <trueToReject>)
# (leave the third argument empty or False to indicate a success. Or set to True to indicate an error)
Perform JavaScript in Web Viewer [ Object Name: "myWebview" ; Function Name: $callbackName ; Parameters: $promiseID, 'Success! Hello from FM!' ]

MISC

Test

npm test

Build

npm run build

Contribute

If you see anything that should be improved please feel free to let me know or send pull requests.

Package Sidebar

Install

npm i fm-gofer

Weekly Downloads

61

Version

1.7.1

License

ISC

Unpacked Size

13.5 kB

Total Files

6

Last publish

Collaborators

  • jwillinghalpern