does a!localVariables() refresh local variables by default?

My team is using Appian 19.2 and since they now have a!localVariables() as a replacement for load(0 and with(), we've been using it explicitly. However I noticed that if I have local variables that query data inside the local variables definition, it queries the data every time something changes inside the form.

Let's assume I have the following code snippet

a!localVariables(

local!id,
local!data = rule!getMyData(id: local!id),

{...rest of code here...}

)

With the above code, the query gets triggered every time local!id changes without having to use the a!refreshVariable() function. This is basically the same behavior we had with with() function, but something I did not expect.

Now if I have the following:

a!localVariables(
local!data = rule!getMyData(),

{...rest of code here...}

)

Now I'm just querying the database and pulling all the data since I don't need to query based on conditions. Is this also querying the database everytime something changes on the form. I can't tell since the data is the same every time and there is no indication as to when the data was last queried. 

Where I'm going with this is, do I need to use the a!refreshVariable() function with queries to avoid the overhead of querying the database every time. The documentation for 19.2 mentions the refresh function in order to update variables, but it does not mention what happens to locals that don't have it. In that case, does it behave like a load() or a with(). Is there a way to tell?


  Discussion posts and replies are publicly visible

  • +1
    Certified Lead Developer

    To confirm, variables defined in a!localVariables(), but without using a!refreshVariable(), will be defined with all the default settings for a!refreshVariable() - this includes the parameter of "refreshOnReferencedVarChange" defaulting to TRUE.  When changing over load() calls to a!localVariables(), this needs to be taken into account - mainly, if defining a local variable to hold the *original* value of some previously-defined value on the form, one would need to set refreshOnReferencedVarChange to FALSE.  All in all, though, the new system should make most standard use cases easier (and it also makes some previously impossible ones possible).

  • Thanks for the reply, this is good to know. But to clarify something, if a local variable calling a query does not reference another variable, it will never refresh when interacting with the form, correct? or will still query the data again every time the user interacts with it?

  • 0
    Certified Lead Developer
    in reply to Jose H.

    What we've been told officially is that refreshOnReferencedVarChange will cause variables to only refresh when a referenced variable changes, and not at any other time.  So far I haven't seen anything that directly contradicts this.  Setting refreshAlways to TRUE (which of course defaults to false) will mimic the old with() behavior.

    A fun trick I've implemented is, if I want to have a "refresh" button/link, i.e. to update a grid with potential recent updates, i'll have it increment a local integer variable, and add that variable name to the refreshOnVarChange list for the query I want to refresh (instead of setting it to refreshAlways, for instance).

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    or maybe a boolean

    local!flipflop: false()

    then in your saveInto, a!save(local!flipflop, not(local!flipflop))

    It's unlikely that you'd ever do the 2 billion plus iterations on a single run through the form needed to reach infinity, but if you ever did...

  • 0
    Certified Lead Developer
    in reply to Dave Lewis

    If you ever see a user clicking refresh once per second for 65 straight years, I hope you'll call me because that'd be a neat sight ;-)