Jump to content

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


This topic is 1216 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • 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.

 

 

 

Link to comment
Share on other sites

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.

 

  • Like 1
Link to comment
Share on other sites

  • 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!

Link to comment
Share on other sites

This topic is 1216 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

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