How would I use JavaScript in 19?

I answered a poster's question on the FMI Forum where he had asked how to extract just the two first capital words from a sentence or until a non-capital word was encountered.

My JavaScript example below handles that but also handles more than 2 words and insures that it quits if not capital letters.

My question is....how would I use this JS function with FMP 18 or FMP 19? I would like to be able to have a script step like "Run JavaScript" * with some way to pass one or more parameters, and have the "Target" of that call (like INSERT FROM URL does) be able to update a field.

Using the web viewer seems like a kludge to me from how I currently understand it.

Just for completeness, my JavaScript is below. I don't spend much time coding in JS so be kind with any code reviews... LOL.


Prints: ADVANCED OUR HAVING

Why post a picture where we can't copy the text easily?

You can run this via JavaScript functions in MBS FileMaker Plugin without web viewer and even on server.

I wasn't actually trying to get that code to work. Instead, I was just asking a general question.

I can already run JavaScript if needed using a simple micro-service method I wrote and a free library:

My question was how integrated (like INSERT FROM URL is) JavaScript is or will be. If JS integration going to be kludgy -- requiring, say, the web viewer, I can always use my micro-service method when I need to run JS (which is almost never).

The example above is just standalone JS code so I would expect a simple way to run it in FMP like I can do with my micro-service.

Just wondering...

Thanks,

I agree - reminds me of the days without InsertFromURL when it was the way to get to external web content. I hope a future version allows to execute JS without WV ..

Besides I am excited for the new ability to use it in an easier fashion then before and if I understood correctly it enables JS running on stand-alone files without internet access. Most of my clients run stand-alone files without internet...

2 Likes

Cool Thanks for your reply. :smile:

1 Like

if you want to run JavaScript in web viewer you can use MBS Plugin or in FileMaker 19 the new script step to run JavaScript (as announced in Roadmap video). Insert from URL will not do that.

I can already run JS from any HTTP-enabled app already using my micro service method. No need to upgrade as I see it now for JS alone. Having said that though, if FMP 19 has a really good JS implementation, I’ll still take a look.

Thanks Christian.

I see the topic of JavaScript and FMP in at least two parts:

  1. Use cases that make use of a WebViewer for the purpose of presentation, e.g. charting, visualizations, hot-rodded list views, drawing, drag-and-drop UI's, map displays etc.

  2. Use cases that simply need a fast calculation engine to plow through large data sets quickly, or perform any other sort of operation that is easily scripted in JS, but otherwise too cumbersome or slow to script/calculate in FMP sans JS. Most of the time when I have this type of use case, it is for string processing -- often to reformat data, or to perform matching with RegExp.

My understanding of the upcoming v.19 JavaScript/WebViewer functionality with respect to the above:

  1. [Visual Presentation]: The upcoming functionality should be a great step forward. With proper use and a little investment of learning, I think it should help to simplify the code needed to have presentations be fully interactive with the FMP solution.**

  2. [JS Calculation Engine]: The upcoming functionality is a small step forward. I am grateful for this step forward, and I take it to be a good sign. Still -- I expect that there will be cases where I prefer to continue using either a plugin or AppleScript to allow for performing JavaScript execution (for non-presentation cases).

Finally:

One hope of mine is that a future FMP release offers a feature that brings an EvaluateJavaScript() function directly into either the FMP Script engine or the FMP Calculation engine similar to what is presently available via plug-ins such as MBS, bBox, and BaseElements.


** Over the last 5 years, the FMP community has evolved admirably with respect to ability with what we can do to make WebViewer presentations interactive -- but, this has required the acceptance of a certain amount of added complexity to such solutions. My hope is that the new features in v.19 will obviate such complexity.

1 Like

Good info Steve,

You know, the web viewer notwithstanding, you also could use a little micro-service and do JS now... :slight_smile:

I wrote this JS capability (about 10 lines of service code) back in 2018.

Happy Coding!

Hi @anon45965781

I often work in environments which permit the use of AppleScript, and plug-ins, but which would push back on a micro-service for the purpose of text-parsing. (Text parsing is one of my most frequent use cases).

So -- my gravitation towards the means that I mentioned in an earlier post is simply a reflection of my response to doing the best that I can, within the constraints that I am often presented.

Were I working in an environment where the client says "we'll pay for and/or host any micro-service that you want to use, but we prefer that you do not use a plug-in, and AppleScript is out of the question", then you can make a solid bet that I'd be writing and/or using micro-services to parse text.

As always, kind regards,

-steve

2 Likes

We can do JavaScript now. No plugin required. I know the webviewer feels like a kludge, and yeah kinda does, but the reality is, it is just an object that has the ability to reach into the browser engine and use it to execute code.

As for 19, the biggest move forward, even while it uses the webviewer still, for now, is that it removes several of the problems around communication and between the web engine and FileMaker. It takes care of the character limitation you get on Windows when passing data around, it handles much of the security issues on the Windows side, you can also focus the call to a specific portion of the JavaScript, and you can execute a FileMaker script much easier with a script step ( some of the what they mentioned in the Preview webinar, and on the presentation at DevCon last year ).

2 Likes

I always appreciate your replies and always learn something useful from them. :slight_smile:

When I’ve ever had push back and I explain to the client what they get using a REST approach, the client normally reacts like ... “why didn’t we do this a long time ago?” Future-proofing their code base, so it's independent of any one software vendor, is often a major plus I don't mention.

I realize ever case is different.

Thanks Steve.