Skip to main content
November 8, 2022
Solved

Local Variable (Query Rule) not get refresh on refreshVariable

  • November 8, 2022
  • 14 replies
  • 0 views

Hi,

we are trying to refresh local variable value on var change but it is not working. PFB Code

a!localVariables(
local!refreshOnVarChange: false,
local!allMessages: a!refreshVariable(
value: rule!DS_QRY_getMessageThread(
returnDatasubset: false,
filters: a!queryFilter(
field: "clientInboxId",
operator: "in",
value: {15,16}
)
),
refreshOnVarChange: local!refreshOnVarChange /*refreshAlways: true, even in this case data is also not get refresh*/
),
local!textBox,
a!sectionLayout(
contents: {
a!textField(
value: local!textBox,
saveInto: {
local!textBox,
a!save(local!refreshOnVarChange, not(local!refreshOnVarChange))
}
),
a!textField(
value: length(wherecontains(true,index(local!allMessages, "isRead", ""))),
readOnly: true
)
}
)
)

Best answer by peter.lewis

Is it possible you have a local variable defined inside of your rule DS_QRY_getMessageThread? If so, you likely also need to add a refresh variable within that rule and define refreshAlways: true.

14 replies

November 8, 2022

Can you try adding refreshOnReferencedVarChange: false in your refreshVariable and check?

local!allMessages: a!refreshVariable(
  value: rule!DS_QRY_getMessageThread(
    returnDatasubset: false,
    filters: a!queryFilter(
      field: "clientInboxId",
      operator: "in",
      value: { 15, 16 }
    )
  ),
  refreshOnReferencedVarChange: false,
  refreshOnVarChange: local!refreshOnVarChange
)

nikhilmAuthor
November 8, 2022

Yes but doesn't work

peter.lewis
Employee
November 8, 2022

Is it possible you have a local variable defined inside of your rule DS_QRY_getMessageThread? If so, you likely also need to add a refresh variable within that rule and define refreshAlways: true.

mikes0011
Brainy
November 8, 2022

I agree with Peter's advice above - assuming the data being fetched is actually refreshing between your attempts to refresh it, what you have written here should basically work (though i'd use a different technique for your "local!refreshOnVarChange" variable).  Please post the code for the rule doing the query operation, as that could be preventing the refresh from occurring properly.

The Expression Guru
csteward
November 8, 2022

Adding my experience here - as this is something I've been tempted to start a thread on as well. 

What I've seen is that if you have a refresh variable that calls a rule which contains a!queryEntity(), it will not refresh automatically.  Simply moving the query out of the rule and into the main refresh variable, resolves the issue.  However, then you have duplicated code if other areas of the application use the rule to query data also.

I haven't exhausted the different scenarios here yet, but I was noticing this last while creating a small message board type app.  The main interface makes a post with a!writeToDataStoreEntity(), I trigger the local variable to refresh by incrementing a reload counter used in refreshOnVarChange, and in no situation can I get it to refresh without pulling the query out of the rule and pasting it in the main refresh variable.  Then, it works flawlessly.

Would love to hear some other experiences on that as well..

csteward
November 8, 2022

And I've been doing a little further testing this morning and was able to get this working with a!queryEntity() within a rule, in some situations, but mainly when a!localVariables() is not used.

mikes0011
Brainy
November 8, 2022
but mainly when a!localVariables() is not used

you need to remember two of the main default properties of the a!localVariables() behavior:

1) it does NOT act with "refresh always" behavior unless set manually (meaning it acts slightly more like legacy "load()" than "with()"...

2) it DOES default to a "refresh on referenced variable change" setting of TRUE - but this ONLY has any effect when a referenced variable is actually changed.

This all means if you're storing a!queryEntity results somewhere in the expression rule in an a!localVariables() variable, then it won't refresh unless you pass a token into the expression rule that acts as a "manually refresh" agent.  This is easyish to do since you can just pass in an integer value like "ri!refreshCounter" etc.

The Expression Guru