Difference in load() with () and other functions

A Score Level 1

Hi folks,

Can anyone please tell me the difference between load(),with(), a!localvariable and a!refreshvariable functions. In what different scenarios are all these used. Is a!localvariable replacement of load and with both ?

It would be better if someone explain them using a code snippet.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    load():  Variables in here only evaluated once when the form first loads.  By "evaluated" we mean run the code that comes after the variable definition.  Since the code is only ever run once, it means we can save values in these local variables that won't immediately get overwritten.  So you're actually required to use load() to make a variable that can be saved to.

    with():  Variables in here get reevaluated absolutely every time the user does anything with the form at all.  This allows for dynamic content, or things that refresh on a button click, for instance.  You don't even need to configure the button to really do anything.  It just causes the with variables to be reevaluated.  If you define an empty with() variable, it gets re-emptied every time the user clicks or types anything, so nothing can be saved there.

    a!localVariables() fully replaces load and with.  The reason load and with aren't relics yet is because essentially every application ever uses only those.  But load() and with() are now essentially tech debt, but tech debt that EVERYONE still has, pretty much.

    Each of your variables inside a!localVariables() should be defined with it's own a!refreshVariable function.  That function takes 2 parameters, where you define what the variable is, and define when that gets reevaluated.  Now you have not only the option of "never" and "any time the user does anything", but also things like "every 30 seconds" or "when this variable changes" or "when some other variable changes".  You should use this, because now you only have to make your with() variables update when it MATTERS whether they update or not.  But you can only do that by porting them over to a!localVariables and defining them with the proper a!refreshVariable.

Reply
  • 0
    Certified Lead Developer

    load():  Variables in here only evaluated once when the form first loads.  By "evaluated" we mean run the code that comes after the variable definition.  Since the code is only ever run once, it means we can save values in these local variables that won't immediately get overwritten.  So you're actually required to use load() to make a variable that can be saved to.

    with():  Variables in here get reevaluated absolutely every time the user does anything with the form at all.  This allows for dynamic content, or things that refresh on a button click, for instance.  You don't even need to configure the button to really do anything.  It just causes the with variables to be reevaluated.  If you define an empty with() variable, it gets re-emptied every time the user clicks or types anything, so nothing can be saved there.

    a!localVariables() fully replaces load and with.  The reason load and with aren't relics yet is because essentially every application ever uses only those.  But load() and with() are now essentially tech debt, but tech debt that EVERYONE still has, pretty much.

    Each of your variables inside a!localVariables() should be defined with it's own a!refreshVariable function.  That function takes 2 parameters, where you define what the variable is, and define when that gets reevaluated.  Now you have not only the option of "never" and "any time the user does anything", but also things like "every 30 seconds" or "when this variable changes" or "when some other variable changes".  You should use this, because now you only have to make your with() variables update when it MATTERS whether they update or not.  But you can only do that by porting them over to a!localVariables and defining them with the proper a!refreshVariable.

Children