Jump to content
the Otter

Changed Behavior in Variable Definition

Recommended Posts

As most people here probably know, the Let ( ) function can be used to define a Local variable. As such, it is possible to build a custom function that defines such a variable, and it is further possible to set said variable to a value including itself. An example would be the following custom function, ErrorList, consisting of the following calculation:

Let ( $ErrorList = List ( $ErrorList ; Get ( LastError ) ) ; "" )

If a Set Variable script step sets the same variable as a custom function like the one above, e.g.

Set Variable [ $ErrorList ; Value: ErrorList ]

…the script step will run appropriately, so long as the contradictory variable—in this case, $ErrorList—is not yet defined. However, once this variable has been defined, executing the preceding script step will cause FileMaker 14 (and perhaps other versions) to suffer an Error #1213 and crash the application. The workaround for this behavior is to have the Set Variable script step set a dummy variable, e.g.

Set Variable [ $x ; Value: ErrorList ]

Even if $x is not referenced anywhere, having a script call the ErrorList function passes the variable $ErrorList to the script’s own context, thus allowing its value to be accessed by later steps in the same script (including subsequent calls to the ErrorList function itself).

In FileMaker 15, this behavior has been changed: local variables defined within a custom function are now valid only within the scope of the function itself, including any recursions. While this alleviates the problem of application crashes, it also results in unexpected behavior when scripts written in earlier versions of FileMaker rely on custom functions to set local variables. When migrating to FileMaker 15, each affected script step must be updated to set the target variable explicitly instead of relying on the custom function to do the work. In other words, the code:

Set Variable [ $ErrorList ; Value: ErrorList ]

which proved fatal in FileMaker 14, is now required grammar for FileMaker 15: FileMaker 15 believes that what happens in the function stays in the function, instead returning the result of the calculation to the variable defined in the Set Variable script step. The FileMaker 14 grammar,

Set Variable [ $x ; Value: ErrorList ]

…thus sets $x to the intended value of $ErrorList while leaving the value of $ErrorList as null.

Unfortunately, this cannot work effectively in a mixed-installation environment: the FileMaker 14 grammar leaves FileMaker 15 clients with unintended null values; the FileMaker 15 grammar causes FileMaker 14 to crash. When upgrading all users to FileMaker 15 is not feasible, the best workaround is to use the FileMaker 14 grammar, then once all relevant script steps are complete, check the value of the intended variable (e.g. $ErrorList) and, if empty, set it to the value of the dummy variable (e.g. $x).

 

ErrorTest.fmp12

Edited by the Otter
Updated Demo File
  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, the Otter said:

In FileMaker 15, this behavior has been changed: local variables defined within a custom function are now valid only within the scope of the function itself, including any recursions. While this alleviates the problem of application crashes, it also results in unexpected behavior when scripts written in earlier versions of FileMaker rely on custom functions to set local variables. When migrating to FileMaker 15, each affected script step must be updated to set the target variable explicitly instead of relying on the custom function to do the work.

I just tested this, and FileMaker 15 custom functions were happy to set local variables that persist outside the function for me. It looks like the ErrorList function in your demo file isn't setting the $Error variable because the custom function chooses not to save error code 0, and the script doesn't trigger any other errors for it to save.

Share this post


Link to post
Share on other sites

Thanks, jbante. Actually, the custom function only ignores error #0 if any error (including 0) was previously recorded. However, you are correct that I have apparently misunderstood the issue: I tried a simpler custom function that sets a variable and it was able to pass that variable to the script.

Despite my misdiagnosis of the problem, there is still a change in behavior: the first version of the script still crashes FileMaker 14, but not 15; and the second version still fails to set $Error to 0 in FileMaker 15, but not 14. I will update the original post once I have more accurately diagnosed the scenario in which this occurs.

Edited by the Otter

Share this post


Link to post
Share on other sites
Let ( [
         #error = Get ( LastError ) ;
         #newError = If ( #error ≠ 0 ; Trim ( #error & " " & scriptStep ) ) ;

It sure looks to me like the function is trying to ignore error code 0, even if there are previously recorded errors. It looks like FileMaker 15 is successfully setting $Error to empty until the first error, and successfully not appending new lines for error code 0. So FileMaker 15 isn't crashing. Great!

Share this post


Link to post
Share on other sites

Yes, thank you. That’s what I get for typing hurriedly. I have fixed my previous comment.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Richard Carlton
      FileMaker Coaches' Corner - Tip 11 - Improve Performance - FileMaker - FileMaker Experts
      https://youtu.be/5D2qoA_S7u8
      Get up to speed with the FileMaker Pro 17 Video Training Course! 
      Top Rated Course by FileMaker Expert, Richard Carlton.  
      http://learningfilemaker.com/fmpro16.php
      Experience Richard's dynamic and exciting teaching format, while learning both basic, intermediate, and advanced FileMaker development skills. With 27 years of FileMaker experience and a long time speaker at FileMaker's Developer Conference ,Richard will teach you all the ins and outs of building FileMaker Solutions.  The course is 50 hours of video content!
      Richard has been involved with the FileMaker platform since 1990 and has grown RCC into one of the largest top tier FileMaker consultancies worldwide. 
      Richard works closely with RCC's staff: a team of 28 FileMaker 
      developers and supporting web designers. He has offices in California, Nevada, and Texas.

      Richard has been a frequent speaker at the FileMaker Developers Conference on a variety of topics involving 
      FileMaker for Startups and Entrepreneurs, and client server integration.

      Richard is the Product Manager for FM Starting Point, the popular and most downloaded free FileMaker CRM Starter Solution.

      Richard won 2015 Excellence Award from FileMaker Inc (Apple Inc) for outstanding video and product creation, leading to business development.

      RCC and LearningFileMaker.com are headquartered in Santa Clara, CA.

      http://www.rcconsulting.com/
      Please feel free to contact us at support@rcconsulting.com
      If you want to explore building I.O.S apps for I Phone or I Pad and deploying those out to the Apple App Store.
       
      Here is a video introduction to our iOS App Training https://www.youtube.com/watch?v=cVxQe_yAshw
      Looking for FM Starting Point free software download: http://www.fmstartingpoint.com
      For More Free FileMaker Videos Check out Http://www.filemakerfree.com
      Visit http://www.learningfilemaker.com for all facets of FileMaker Award Winning Video Training.
      Please Visit Our Channel: https://www.youtube.com/user/FileMakerVideos Please Subscribe While There.

      Please Comment, Like & Share All of Our Videos.

      Feel Free to Embed any of Our Videos on Your Blog or Website.
      Follow Us on Your Favorite Social Media
      https://www.facebook.com/FileMakerVideos
      https://twitter.com/filemakervideos
      https://plus.google.com/+FileMakerVideos/videos

      Filemaker Pro 17 Training Videos
      FileMaker 17 Videos
      Filemaker Pro 17 Video Course
      #FileMakerVideos
      #FileMakerTrainingVideos
      #WhatisFilemaker17
      #FilemakerPro17Training
      #Filemaker17VideoTutorial
      #FilemakerPro17Videos
      #FileMakerCoaches'CornerTip11
    • By pandsmarine
      Hi guys,
      I’m brand new working with FM and would like your help with a calculation if I may. I want a calculation to display an estimated number of paint tins needed to paint a boat based on it’s length and width. With this information I would also like the cost of the estimated paint. I'm assuming IF can not be used as there are too many variables, can CASE?
      With the boats width, I've got anything over 7 classed as wide, so I've been using Jobs::BoatWidth > 7 to define narrow and wide (only two classes of widths).  I'm using the table below to give our customers a rough idea at the moment but would like information to be displayed in FM specific to boats length and width for each customer after entering that data: Jobs::BoatWidth and Jobs::BoatLength. Cost of each tin is £26.32. Hope I haven't left anything out and thanks in advance.

    • By H
      hi
      i have a table with 4  fields
      field 1 =  number result 1
      field 2 =number result 2
      field 3= percentage result
      field 4 = calculation by taking in whichever is lower field 1 or 2 and multiplying by field 3
       
      the question now is how do i script the calculation it should pick up which ever is lower but ignore if field is empty.
      i hope i am clear , i would appreciate if someone could help me out with this calculation. 
       
    • By docasar
      Hello,
      I am still very amateur on Filemaker so i hope my question does make any sense.
      I am trying to write a script that would basically import order information from an email and convert it, first in a new account (if the customer does not exist) and later create a Sale Order. So far, I have managed to do that, but the problem i find is when trying to convert the sale order into an invoice. Since this order comes from our webshop when we receive the email means it is paid, so my aim is that when creating the invoice from the Sale order, this would be marked as paid and set the amount due to zero.
      This would sound a very easy task, but since our solution incorporates a payments module to manage the payment of an invoice, when i try to incorporate the payment entry within my script, there is when all the trouble starts. For some reason, it gets lost in its way when runnig the script and returns a partial payment all the time. The weirdest thing is thet if I run the script on debug mode, then all works perfectly, so my guess is that the issue may be related to the speed of the script.
      So, is there any recomendation as for where to put a pause script step so the script will work also when run automatically?
      I have tried every possible combination of long script, shorter with other scripts inside, perform script on server... and all the time something is wrong ;(
      Thanks a lot for any insight thst would help us move forward, since we have been trying to solve this for a week already.
       Best
      Luis
    • By userfmp
      I have the following:
       
      Table 1 – Expenses
       
      Field A: Date
      Field B: Concept
      Field C: Amount
       
      Table 2 – Flight Time
       
      Field D: Date
      Field E: Flight Time (in hours)
       
      I need a report that will give me the expense cost per hour, i.e. the total of Field C divided by the total of Field E.
       
      Table 1 and Table 2 are not related. What relationship must I establish between them to obtain my desired result?
       
      If establishing a relationship between the tables is not the answer, how else can I achieve the figure I need?
       
      Thank you for any help that can be provided. 
  • Who Viewed the Topic

    9 members have viewed this topic:
    ryan360Works  sh2658  Warren  Joshua Rivers  amallison  Lee Smith  Lola  Christian Chojnacki  Tim Anderson 
×

Important Information

By using this site, you agree to our Terms of Use.