Custom Function Database - Part 4

When you know just a little part of how FileMaker works under the hood, you can come up with creative solutions to everyday problems. Take web services as an example. They use defined structures such as XML and JSON. And, when you consider that you’re using this third party defined structure and the need to mix in your own data, you want to find the easy way to solve the problem.

In my case, I really like the path of least resistance. Of course, there are many ways to solve a problem. Let’s consider a FileMaker script. It can be self contained and have no dependencies on any other FileMaker elements. It can be called by another script and can be completely disassociated from any and all context. Context, within FileMaker, if you didn’t know, is the situation where a script can only do something if it’s executing in the right place. The right place would be the current Layout in which the script is running.

If we don’t fight context, however, and simply make our scripts only operate within the proper context, then we can simply handle the error when the right context doesn’t exist and let the proper people know about it.

I’ve coded solutions in both ways. Context independent and context sensitive, and it really boils down to use, preference and perspective. So, for this video we’re taking the context approach and using FileMaker’s ever so easy ability to merge in field data or global variables into text objects in order to make things easy for us to copy our Custom Functions to the clipboard. This information in this video and file have “Oh so many implications.”

AttachmentSize
CustomFunctions04.zip148.7 KB

Comments

looks like you don't need the "data:text/html," appended to the HTML in the web viewer calculation now in version FM 15.... came across when I could not get my web viewer to draw when the file was opened in FM Pro 14 Advanced.

"data:text/html," & Functions::html

The layout text block “text.snippet”, as described in Custom Function Database - Part 4, causes Database Design Report to hang.

Simply trying to copy/cut the text block “text.snippet”, containing the clipboard xml, causes FMP to hang as well. Copying/pasting the raw text doesn’t cause a problem.

The problem lies with "<Calculation><![CDATA[<<function>>]]></Calculation>”.

Cutting and pasting a text block that contains only "<Calculation><![CDATA[]]></Calculation>” results in a text block containing only “</Calculation>”.

Using text blocks as retrievable storage is a useful technique but can cause unexpected side effects - at least in this case.

Looks like a script calculation is the best alternative.

———— Copy Function ————

Let ( [
~snippet = "<fmxmlsnippet type=\"FMObjectList\"><CustomFunction id=\"0\" functionArity=\"" &
Functions::arity & "\" visible=\"True\" parameters=\"" &
Functions::parameters & "\" name=\"" &
Functions::name & "\"><Calculation><![CDATA[" &
Functions::function & "]]></Calculation></CustomFunction></fmxmlsnippet>";

~isWindows = Get ( SystemPlatform ) ≠ 1;
~format = If ( ~isWindows ; "Mac-XMFN" ; "dyn.ah62d4rv4gk8zuxngm2" );
$$COPY.RESULT = BE_SetClipboardText ( ~snippet ; ~format );
$$COPY.MESSAGE = If ( $$COPY.RESULT = True ; "Copied to clipboard" )
];

"text.copyresult"

)