JavaScript Changes in FileMaker 16

Have you heard of Carafe? Our free, open-source tool makes it easy to implement JavaScript in your FileMaker solution. Learn more.

FileMaker 16 introduces a new security setting that could affect solutions using JavaScript. This extended privilege is called “fmpurlscript” and allows URLs to perform FileMaker Scripts. The “fmpurl” is used to reference FileMaker applications, much like “http” is for referencing web applications. You can use an “fmpurl” with JavaScript to get information from a web script to your FileMaker application.

We have covered FileMaker and JavaScript before. Here are just a few previous blog posts and sample files:

DevCon 2017 Session

Jeremy Brown has an upcoming session at DevCon this year as well, where he will go into more depth on this topic.

Web Viewer Integrations Presentation Description

The web viewer object is an extremely versatile object that allows a developer to integrate deeper functionality into a custom app using the languages of the web, HTML/CSS and JavaScript.

In this session, you’ll explore a standard way to integrate common web libraries, including setting up an integration in FileMaker, manipulating it, and gathering data using some of the new functions of FileMaker 16. Discover best practices that are used to make this as easy as possible to set up deeper functionality.


New FileMaker 16 Functions

FileMaker 16 also comes with helpful functionality for getting data back and forth from a JavaScript-based solution. These include functions for JSON (JavaScript Object Notation), which you can now handle natively in FileMaker. For more on these, please see the following blog posts from my team members:

Also, Anders Monsen has a DevCon 2017 session on JSON that may be of interest as well.

Leveraging JSON in Your Custom Apps

JSON is a data language that’s becoming increasingly popular in the tech world and you can integrate JSON with FileMaker for your data interchanging needs.

In this session, you’ll learn the various ways in which to leverage JSON in your custom apps. Take real world examples and investigate integration capabilities by contrasting FileMaker 15 (without plugins and 3rd party tools) and FileMaker 16 (using 16’s new JSON functions), including approaches for dealing with improperly formatted JSON. Recommended Background.

Updated JavaScript Samples for FileMaker 16

This new release has been a great opportunity to update a few examples I have written that use JavaScript. These are also freely available.

These particular examples demonstrate techniques that do not output a visible result in a Web Viewer. Rather, they utilize JavaScript functionality to extend FileMaker and return data to FileMaker in a useful way.

Each of these has been updated for FileMaker 16.

FM-js_Barcode

A question posed in the FileMaker Community asked if there was a way to save an image generated from JavaScript and save it in a container field. This solution uses code from the Github repository of Johan Lindell, linked below.

Since storing as an image in a container field allows for clean printing in all platforms that FileMaker supports, this is a preferred way to generate and store barcodes. You don’t need to install anything on client machines, like 3rd party plugins or maintained fonts.

  • Github Project used here.

Some barcode types may have requirements on the values they can represent. For example, your EAN type must be a 13 digit number. Check the documentation for the barcode type you use before implementing this in your solution.

FileMaker 16 also added better support for Windows versions where long URLs are not supported and may fail. Note that this uses the user clipboard to transfer data from the web viewer to a field.

FM-jsSON

This file uses JavaScript to parse JSON. Since JSON was built specifically to be used by JavaScript, it makes sense to utilize the JavaScript engine via the Web Viewer in Filemaker Pro and FileMaker Go.

You can easily adapt this to your solutions as needed. There are minimal fields involved, and a couple scripts that drive the solution.

To run the demo:

  1. Modify the object you want to reference in the field provided. Note that arrays start at zero (0).
  2. Click the “Get Object” button.
  3. View the results.

The JavaScript used is in the Resources table, and you can modify it for your use from there.

FM-js_ExcelSheets

This file uses JavaScript to create an XLSX file. You can easily adapt it to your solutions as needed. There are minimal fields involved, and a couple scripts that drive the solution.

To run the demo:

  1. Check the boxes to select the sheets to include in your Worksheet.
  2. Click the “Save as Excel” button.
  3. View the results. If “Automatically Open” was checked, a copy is exported to the desktop and launched.

The JavaScript used is in the Resources table; you can modify it for your use from there.

Use the JavaScript Library from Github here.

Please view the licensing information for each piece.

FM-js_ValidateXML

A question posed in the FileMaker Community asked if there was a way to validate XML. Interestingly, there are solutions for this in JavaScript that we can use to pass a result back to a FileMaker script.

By adjusting some JavaScript related to finding unclosed tags in XML, you can have it use a FMP URL to call a script in the parent FileMaker file and pass the result back as a script parameter.

See a sample JavaScript from Stack Overflow here.

The source URL referenced on the Stack Overflow page no longer works; use the XML Validator instead.

Carafe Tutorials

Our free, open-source tool, Carafe, allows you to easily download, configure, and deploy a bundled Javascript library into FileMaker.

18 thoughts on “JavaScript Changes in FileMaker 16”

  1. Hi Mike,

    The Javascript xlsx demo is awesome, thank you. Did you consider setting the field names into the column headers rather than the first row or formatting the first row with a background colour for example?

    Javascript is not my area, so it would be helpful if you could point me in the right direction…

    Thanks

  2. Mike,

    I did look at the link before I posted and was rather put off by the number of files in the repository – I tried searching, but without much success. I thought it worth asking incase you could say look in file xxx in the repository 🙂

    Thanks anyway – it’s still a great technique…

    1. Right, you don’t need to download those files, but if you scroll down the page on that github repo, the documentation from the Readme is there. Looks like maybe the headers are generated from the keys in the JSON you pass it, but I have not tested that.
      Mike

  3. Hi Mike,

    I used your template successfully; thank you very much!

    In the excel file produced I would like to format some cells as USD currency, highlight in yellow some empty cells, and format the text of a specific column in red font. Is there a way to do that?

  4. FM-js_ExcelSheets doesn’t seem to like Filemaker 19. Any chance you could point me in the correct direction to re-establish compatibility please?

    Many thanks in advance,
    Stephen

    1. It actually still worked in Mac, but recent versions of FileMaker for Windows broke likely due to switch to Edge for rendering web viewers and no longer being able to set the clipboard. Fortunately this does work when using the javascript support added to FM to be able to call javascript functions from FM and for javascript to call FM script and pass parameters. I have updated the sample file on github and will work cross platform now.

      1. Cannot thank you enough, for both your knowledge and speed of reply!
        I’m off to convert my existing setup using your new version.

        Sincere thanks once again,
        S.

      2. Stephen Foster

        I’m finding this update a little glitchy – I can run it a few times and nothing happens and the next time it’ll generate the spreadsheet? Filemaker 19 (on Windows) also hangs for about 20 seconds once a spreadsheet is successfully generated.

        Anyone else experiencing similar behaviour?
        S.

      3. Stephen Foster

        Apologies for pestering yet again, but I am struggling to add more than the three worksheets used in the example – in fact, it fails if I don’t name all my elements company, address, contacts!
        I had this working with 14 sheets with the old version and it was just a case of tweaking the ws and ws_name in the Save_XLSX script and adding these worksheets into the Resources::js field.
        The js doesn’t look much different, but is there some limitation on worksheet numbers and naming at all?
        Sincere thanks in advance,
        S.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top