I need some help with setting a Global Variable in a LET() Function. My question is can a Global variable be assigned to a Let function variable?
I'd like to use the Global variable to either set a field or as a Global Merge variable on a layout
In my opinion, it's better to use set variable and explicitly set the variable to a value, but:
Let ( $$GlobalVariable = 5 ; put any expression that works here )
Will assign the number 5 to the global varialbe named $$GlobalVariable.
I'm not a big fan of this method as it updates a global variable as a "side effect" of whatever else the calculation is doing and that tends to hide the variable modification from view--making it harder to debug if an issue arises.
In my opinion...
And we all have them. YMMV!
Yep and I do use Let to assign values to a $variable or $$Variable, but choose not to unless there is an overriding reason to do so.
Many developers, myself included, have used Let inside a Hide Object When or Conditional Format expression to load variables with values, but I stopped doing that several years ago when a FileMaker engineer advised against it. Don't know if his advice is still valid, but at the time, they were planning changes in how a layout updated that might cause issues for such a method in upcoming versions. I thus started using an appropriate script trigger and set variable as a way to get the same result.
I don't hide any variable assignments inside anything except define fields or script steps that use the calc dialog. Use of Let() for multiple assignments within those two places is a preference. Mostly I stick to where I can print the field defs or scripts (to PDF). Those other hidden place are too hard to remember!
As we have debated in other threads, even in those calculations, the variable assignments can be hidden when you review them from the scripts workspace and thus still can be missed. (Having to open additional dialogs and inspect the contents when reviewing code really slows me down, I don't want to do that if I don't have to, this applies to other script steps as well as those where a variable might get a value assigned via the let function--scripted finds that store criteria inside the step would be another example.)
Hiding the assignment inside a field definition, in my opinoin, is even worse as that really hides the code from view during such code reviews. Printing stuff to PDF isn't an option that really works for me, too easy for them to be out of date and too much trouble to use for review when you can simply open a copy of the solution and look at what's there instead (if you don't bury such details unnecessarily.) This preference is also colored by the fact that I am responsible for a 100+ file solution where keeping track of such PDFs would be a major nightmare all its own.
Retrieving data ...