Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

Problem dealing with constants


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

Recommended Posts

Posted

Hi guys I have a problem with constant values.

 

The constants I deal with are currency exchange rates, I have to set these constants once per year (maybe).

 

Upon reading the topic http://fmforums.com/forum/topic/64043-best-way-to-store-access-constants/

 

I set up a table named gConstants and 1 calculation field named gConstants::EUR_to_USD, calculation result EUR_to_USD = 1,300 and I set it to global storage (options->storage->global).

 

If I create a new record on this table (first record)  the calculation field gets set to 1,3 and everything works fine: there's a script which uses the calc field value and sets another field accordingly on an unrelated table.

 

The problem is that if I close the database and open it up again the table gConstants shows 1 record and no values for the field gConstants::EUR_to_USD.

 

So I tried to set up another field on gConstants named gConstants::EUR_to_USD_Main, fieldtype: Number and I set gConstants::EUR_to_USD fieldtype:Calculation and Calculation result: EUR_to_USD = EUR_to_USD_Main (I guess this is what user LaRetta means by " mirroring the fields in it as global calculations" in the topic previously linked).

 

Again, everything works fine if I create a new (single) record in table gConstants, but after closing and opening the database there's 1 record on table gConstants with the field gConstants::EUR_to_USD_Main displaying the value 1,3 I previously entered but no value on the global calculation field gConstants::EUR_to_USD.

 

I guess I'm making some sort of STUPID mistake but can't understand where. Can you please help me? 

Thank you very much!

Posted

So I tried to set up another field on gConstants named gConstants::EUR_to_USD_Main, fieldtype: Number and I set gConstants::EUR_to_USD fieldtype:Calculation and Calculation result: EUR_to_USD = EUR_to_USD_Main (I guess this is what user LaRetta means by " mirroring the fields in it as global calculations" in the topic previously linked).

 

....aaaaand now it works. what. I'll recap everything I did so that maybe you can help me avoiding mistakes.

 

Table name: gConstants

 

Fields:

EUR_to_USD_Main (type: NUMBER)

 

EUR_to_USD (type:CALCULATION) Calculation Result: EUR_to_USD = gConstants::EUR_to_USD_Main / Storage Options: Global /Indexing: unticked do not store, recalculate when needed / unticked Do not Evaluate when all reference fields are empty.

 

I created the first (and only) record on gConstants table, I filled in the field gConstants::EUR_to_USD_Main with a numeric value. Closed and reopened db and BAM! the field EUR_to_USD is  still showing its value. But I'm worried.  :ike:

Posted

Global fields are unique to each user in a multi-user solution, and will revert to the value entered when the file was last accessed locally upon re-opening.  One or both of these behaviors is what tripped you up.

 

Since gConstants is a one-record utility table, make all fields in it non-global (including a number field EUR_to_USD), and relate TOs of it to each table which needs to access it with a Cartesian (X) relationship.  YourTable::<any field> X gConstantsTO::<any field>. 

 

Then you don't need the calculation field at all in gConstants.  In your main table, you can have a field EUR_to_USD_Current, which would be a number field with an auto entered  looked-up value gConstants::EUR_to_USD, and use that field for your USDPrice calculation.

 

This way, when the exchange rate changes next year and you update gConstants::EUR_to_USD, all your previous records don't get erroneously changed.  All of your newly added records, though, will use the current exchange rate.

  • Like 1
Posted

Instead of having a Constant field which is global, why not have a table called, let's say, Currency Rates, wher the current exchange rates are recorded. Choose a baseline currency (USD would be the most obvious example) and have records recording the current rates. You can have as many exchange rates For different currencies as you wish, each in a separate record, and simply look up the value when needed. If the rate changes, you update the record in Currency Rates. Your history will be preserved this way.

Posted

Global fields are unique to each user in a multi-user solution, and will revert to the value entered when the file was last accessed locally upon re-opening.  One or both of these behaviors is what tripped you up.

 

Since gConstants is a one-record utility table, make all fields in it non-global (including a number field EUR_to_USD), and relate TOs of it to each table which needs to access it with a Cartesian (X) relationship.  YourTable::<any field> X gConstantsTO::<any field>. 

 

Then you don't need the calculation field at all in gConstants.  In your main table, you can have a field EUR_to_USD_Current, which would be a number field with an auto entered  looked-up value gConstants::EUR_to_USD, and use that field for your USDPrice calculation.

 

This way, when the exchange rate changes next year and you update gConstants::EUR_to_USD, all your previous records don't get erroneously changed.  All of your newly added records, though, will use the current exchange rate.

 

Thank you for this advice, I guess this is the route I'll be taking.

 

I have created three number fields in gConstants table:

 

EUR_to_USD

EUR_to_CHF

CHF_to_USD

 

and three Number fields on the greenTable

 

EUR_to_USD_Current - Lookup to gConstants::EUR_to_USD

EUR_to_CHF_Current - Lookup to gConstants::EUR_to_CHF

CHF_to_USD_Current - Lookup to gConstants::CHF_to_USD

 

And I linked them with Cartesian Product as you suggested in this way:

 

Cart_prod.png

 

Then I'll have a script on the greenTable using the values of EUR_to_USD_Current field.

Is this what you meant?

I don't understand why I should have Cartesian Product Relationship "X" instead of "=" relationship.

 

Shall I create a parent key on gConstants (const_ID) and use it as foreign key (const_ID) on the greenTable and relate them with Cartesian Product instead of relating the single fields to each other as I did in the picture?

 

Thank you for your help.

Posted

In a Cartesian relationship, every record in one table is related to every record in the other, regardless of the fields you use to define the relationship.  Thus, you can relate GreenTable::ID to gConstants::SomeField, and every record in the green table will be able to access gConstants::EUR_to_USD or CHF_to_USD or any gConstants field.  So, you don't need to create a dedicated key field, and you don't need to relate three fields to 3 fields as indicated in your diagram.

Posted

Ok doughemi, I tried your method and it's not working.

When I create a record on my greentable which has fields who lookup to gConstants fields none of them gets filled in. There's surely something I'm doing wrong, I'll try to figure it out myself.

Posted

It works for me.

 

attachicon.gifcruijff.fmp12.zip

 

Thank you very much. That's the way I did it in my file, except it's working.

 

What exactly are you worried about?

 

Nothing I was just joking. The thing I didn't understand was about how global fields (in a shared db) work, reverting to their existing value when its content is changed from a client.

How can one effectively change the content of a global field without accessing from the host? In a shared solution with FMS it would be quite annoying to "close" the db and open it just to change global fields.

 

Edit: It seem you can't from the Notes first line http://www.filemaker.com/12help/html/add_view_data.4.48.html

Posted

I haven't tested this for a while and apparently there have been some changes:

http://fmforums.com/forum/topic/89185-filemaker-12-migration-server-side-scriptmaker-does-not-set-global-fields-anymore/?p=409375

 

If you want to play it safe, run a start-up script to set global fields (not calculations) to the values stored in preferences (single record, non-global fields). That way you can be sure each session starts with the current preferences values in its globals - and you do not need to litter your RG with extraneous relationships.

Posted

 

How can one effectively change the content of a global field without accessing from the host? In a shared solution with FMS it would be quite annoying to "close" the db and open it just to change global fields.

 

 

What this points to is that you are using globals for what they are not truly supposed to be used.  Globals are for temporary and user-session specific bits of data.  If you want to store data that is available to all users and can be changed, then you should not use globals as the main storage vehicle for that data.

Posted

Thank you Wim Decorte. I have abandoned the idea of using global fields for this issue and effectively implemented doughemi method. Thank you all.

This topic is 4068 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.