Hi,
We have a simple code to add a record in a table, and we need to display the total count result stored in a local variable (getting the result from an ER that simply counts the records in the table).
When we execute the code, the record is well added in the table, but the refresh of the variable is not down (or the ER is not called ?).
We are using a count variable to make a refresh with a refreshvariable function but it doet not work.
Are we forgetting something ?
a!localVariables( local!count: 0, local!nb_element: a!refreshVariable( value: rule!CD_Count_CD_Test1(), /* count the nb of records */ refreshOnVarChange: { local!count } ), local!new_bank: ( 'type!{urn:com:appian:types:crm}CD_Test1', { code: 1, libelle: "Un" } ), local!erreur, local!success, local!cancel: false, { a!cardLayout( contents: { rule!SHARED_CardsTitle( icon: "address-book", label: "Bank testing" ), a!boxLayout( label: "Add a bank", contents: { a!columnsLayout( columns: { a!columnLayout( contents: { a!buttonLayout( primaryButtons: { a!buttonWidget( label: "add", icon: "check", saveInto: { /****************************************************************************************/ /* Save the new bank */ a!writeToDataStoreEntity( dataStoreEntity: cons!CD_Test1_cons, valueToStore: { local!new_bank }, onSuccess: { a!save(local!count, local!count+1), a!save(local!success, now()), }, onError: { a!save(local!erreur, now()), } ), /* a!save( local!nb_element, rule!CD_Count_CD_Test1() ),*/ }, submit: false, style: "PRIMARY" ) }, secondaryButtons: a!buttonWidget( label: "Cancel", saveInto: { a!save(local!cancel, true), }, submit: false, validate: false ) ) } ) } ) }, showWhen: true, style: "#980000", marginBelow: "STANDARD" ) , a!textField( value: local!nb_element, ) }, showWhen: true, marginbelow: "STANDARD" ) } )
Discussion posts and replies are publicly visible
What you have here seems essentially correct. What do you have in "rule!CD_Count_CD_Test1()" though?
Hum... I've found myself the reason : the refresh failed because of the local variable in the ER.But why ?
- Refresh is failing :
a!localVariables( local!data: a!queryEntity( entity: cons!CD_Test1_cons, fetchtotalcount: true, query: a!query( logicalexpression: a!queryLogicalExpression( operator: "OR", filters: { }, ), pagingInfo: a!pagingInfo(1,-1) ) ), local!data.totalCount )
- Refresh is OK :
a!queryEntity( entity: cons!CD_Test1_cons, fetchtotalcount: true, query: a!query( logicalexpression: a!queryLogicalExpression( operator: "OR", filters: { }, ), pagingInfo: a!pagingInfo(1,-1) ) ).totalCount
Try reverting back to the original expression rule but set local!data to use a!refreshVariable with a "refreshAlways" set to TRUE.
Variables declared in a!localVariables (but without a!refreshVariable() setting overrides) will only refresh when referenced variables (if any) are updated. RefreshAlways completely bypasses this (but use it carefully when a query could become more load intensive).
A different way to handle it would be to pass your "local!count" down into the Expression Rule and give the local variable there its own "refreshOnVarChange"; this would allow you to essentially "manually" refresh the value held in the expression rule.
Thanks a lot Mike.
Your first suggestion works fine but I'm surprised to have to test such a simply code so carefully.
Refreshing data can be tricky, but the neat part is that once you get used to it, this new system gives us very tight control over what data to refresh and why/how/when. It also allows us to automate a bunch of things by chaining together auto-updating values; in the old days this required having manual saveIntos repeated all throughout a form.
Ok I undestand (and more I encounter this kind of problems, more I understand the Appian refreshing logic ;-) )