Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Calculation Field with Custom Function only working as Text Field vs Number

Featured Replies

  • Newbies

Hi,

I am trying to better familiarize myself with Custom Functions and am going through some very basic exercises to get an understanding of how they can be used in calculations, and also make use of global variables as parameters.   Along the way I've run into what to my eyes seems a bit odd. I'm hoping a more experienced developer can help me understand why. I've created the following:

Custom Function:

name: TESTFUNCTION

Parameters: PAR1; PAR2

TESTFUNCTION( PAR1; PAR2 ) = PAR1 + PAR2

Calculation Field:

= TESTFUNCTION( $$PAR1; $$PAR2 )

*Calculation result is Number

Script: (to set the variables $$PAR1  and $$PAR2)

1. Set Variable [ $$PAR1; Value: $$PAR1 + 1 ]

2. Set Variable [ $$PAR2; Value: 2 ]

I've placed the field on a layout and am expecting that when I run the script, the value in the field will change, but the field data is not changing.  However, when I change the properties of the calculation field such that the calculation result is text, the value does change as expected.  Can someone help me understand why this is not working when the calculation is set to output a number.  

 

Thanks in advance!

 

Daniel

 

ps If there is a better for for this topic amongst the many forums, I apologize.  I am currently using FM Advanced 17 so this was the appropriate place I could find.

 

 

 

If I understand your question correctly (which is not at all certain), it has very little to do with custom functions. The real issue here seems to be when does a calculation field evaluate. If it is unstored, it will recalculate on every screen redraw. Otherwise it will recalculate when a referenced field is modified.

Your field's formula references only variables, not fields. Modifying the variables' value is a non-event as far as the field refresh goes. If you want the see the field change after running your script, add a Refresh Window [] step to the script. Or give the field an object name and do Refresh Object []. (The field must be unstored for either of these to work.)

 

4 hours ago, overdhump said:

when I change the properties of the calculation field such that the calculation result is text, the value does change as expected. 

I don't think that is possible. Sure, if you change the field's definition, it will recalculate. But it will not keep recalculating every time you run your script.

 

  • Author
  • Newbies

Thanks for the help and you certainly understood my issue correctly...that is in fact all true and thanks for straightening it out for me.  I was so sure that it was updating when I changed the field definition such that the calculation resulted as text, but I must've been chasing my tail.  Appreciate the help.  Custom functions aside, that is very helpful information regarding calculation fields.  Cheers!

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.