Skip to main content
April 20, 2021
Solved

Expression rule with same rule inputs should produce different results

  • April 20, 2021
  • 9 replies
  • 0 views

I have the following situation:

- search text field for entering the client's ID

- ADD button that does the search and adds the client to the grid

- pretty complex UI which has this part regarding ADD button:

a!buttonArrayLayout(
                      buttons: {
                        a!buttonWidget(
                          label: "Add",
                          saveInto: {
                            a!save(local!addbButtonSwitch, not(local!addbButtonSwitch)),
                            a!localVariables(
                                local!client: a!refreshVariable(
                                  value: rule!APP_getclient(
                                  clientGroup: fv!item.id,
                                  clientCheckCdt: ri!clientCheck_cdt,
                                  clientRequestCdt: ri!request_cdt,
                                  searchString: trim(
                                    local!searchId[fv!index]
                                  ),
                                  global: not(
                                    fv!item.local
                                  ),
                                  isValid: local!isValid
                                ),
                                refreshOnVarChange: local!addbButtonSwitch
                                ),

Action order is as follows.

- client with some ID does not exist inside some remote database

- user searches for this client's ID via mentioned UI

- user receives the message NOT FOUND inside the text field (message replaces the ID that was used for search within local variable local!searchId)

- user adds client's data to the remote database without navigating away from the current UI (opens new tab and adds client via some third party application)

- user enters the same ID and clicks ADD again

- user should successfully add the client to the grid since it exists inside the remote database

However, this doesn't happen.

Since there are multiple grids on screen ("client buckets"), attempt to add the same client to any other bucket is successful. Attempt to search for another client, adding it to the grid and then searching for the first client again is also successful.

But, attempt to add the first client to the grid where it was searched for before it was added to the remote database results always with the message NOT FOUND.

It seems that this local variable local!client is never refreshed if rule inputs for rule rule!APP_getclient are unchanged.

I've tried to add some "switch" variable (local!addbButtonSwitch) that will cause the local!client to be refreshed upon each click on ADD button but it seems that result stays the same - empty result set since that client didn't exist upon first search attempt.

Is there any way to force the expression rule rule!APP_getclient to return new result set even though rule inputs are unchanged?

Just to mention, I do not have an option to change rule inputs or paradigm that uses array of search IDs or anything like that. This is the legacy code and cannot sustain major refactoring at this point. Maybe I can modify expression rule itself or the way it is referenced inside this a!localVariables block?

    Best answer by stefanhelzle0001

    That is a quite complex scenario. My approach would be to drill down and add debugging information along the way. There is a plugin "Log a Message" which allows you to write to the tomcat-std-out log.

    This way you should be able to find out what is going on behind the scenes.

    9 replies

    stefanhelzle0001
    Brainy
    April 21, 2021

    Appian caches DB calls. If the inputs do not change, then it might return the cached values. And, by any chance, how is the expression APP_getClient() built? In case there is local variables, it can happen that these are not refreshed. This can happen with load() and a!localVariables not set to refreshAlways.

    ivanm0004Author
    April 21, 2021

    It is built with with() and contains local variables. One of the local variables calls another expression rule which then fetches client from the remote database (query entity). Should I try with a!localvariables and refreshAlways instead of with? Are there any benefits?

    stefanhelzle0001
    Brainy
    April 21, 2021

    with()/load() is the old way, a!localVariables is the new way. Variables inside with() are reevaluated on each interaction. There is no real benefit in refactoring this. But you have to make sure that the whole chain of calls and local variables uses with() or a!localVariables with refreshAlways.

    Do you have any chance to find out whether this is a DB caching issue?