So I'm building an interface and part of it the user can change address and add credits to his account, but when i add credits I need to update the browser in order to display the new balance value, I've been told I need to use refreshVariable but doesnt seem to work for me can someone help? heres a code snippet:
a!localVariables( local!filter, local!imagesdetail, local!selectedtab: 2, local!addingaddress: false(), local!addcredits: false(), local!user: rule!AS_Get_Account(loggedInUser()), local!newaddress, local!addedcredit, local!changeaddress:{name:loggedInUser(),balance:local!user.balance,address:local!newaddress}, local!changedbalance:{name:loggedInUser(),balance:(if(isnull(local!addedcredit),null,local!user.balance+local!addedcredit)),address:local!user.address}, local!filtered: rule!AS_Get_By_Category(local!filter), local!visivel, local!id, local!querycomments: rule!AS_Get_Comments(local!id), local!info: rule!AS_Get_By_Id(local!id), local!rating: 0, local!totalstars: 10, local!score: 5, local!comment, local!totalorder, local!stored:{productId: local!info.id, rating: local!rating}, local!comments:{productId: local!info.id, comments: local!comment, user: loggedInUser(), date: today()}, local!cart: rule!AS_Get_Cart(), local!carttest:{name: local!info.name, stock: local!info.quantity, price: local!info.price, quantity:1, total:null()}, ... a!sectionLayout( label: loggedInUser(), contents: { a!sideBySideLayout( items: { a!sideBySideItem( item: a!richTextDisplayField( label: "Shipping Address:", labelPosition: "ABOVE", value: local!user.address ) ), a!sideBySideItem( item: a!richTextDisplayField( label: "Account's Balance", labelPosition: "ABOVE", value: "$" & local!user.balance ) ) } ), a!sideBySideLayout( items: { a!sideBySideItem( item: a!richTextDisplayField( labelPosition: "COLLAPSED", value: { a!richTextIcon( icon: "house-damage" ), " ", a!richTextItem( text: { "Update Address" }, link: a!dynamicLink( label: "Dynamic Link", saveInto: local!addingaddress ), style: { "STRONG" } ) } ) ), a!sideBySideItem( item: a!richTextDisplayField( labelPosition: "COLLAPSED", value: { a!richTextIcon( icon: "plus" ), " ", a!richTextItem( text: { "Add Credits" }, link: a!dynamicLink( label: "Dynamic Link", saveInto: local!addcredits ), style: { "STRONG" } ) } ) ) } ), a!sideBySideLayout( items: { a!sideBySideItem( item: a!textField( label: "Text", labelPosition: "COLLAPSED", placeholder: "Add New Address Here", value: local!newaddress, saveInto: local!newaddress, refreshAfter: "UNFOCUS", showWhen: local!addingaddress, validations: {} ) ), a!sideBySideItem( item: a!buttonArrayLayout( buttons: { a!buttonWidget( label: "Update", saveInto: {a!save(local!addingaddress, false()), a!writeToDataStoreEntity(cons!AS_DataStore_Account_Pointer,local!changeaddress) }, style: "NORMAL", showWhen: local!addingaddress ) }, align: "START" ) ), a!sideBySideItem( item: a!textField( label: "Text", labelPosition: "COLLAPSED", placeholder: "Place the Amount", value: local!addedcredit, saveInto: local!addedcredit, refreshAfter: "UNFOCUS", showWhen: local!addcredits, validations: {} ) ), a!sideBySideItem( item: a!buttonArrayLayout( buttons: { a!buttonWidget( label: "Add", saveInto: {a!save(local!addcredits,false()), a!writeToDataStoreEntity(cons!AS_DataStore_Account_Pointer,local!changedbalance) }, style: "NORMAL", showWhen: local!addcredits ) }, align: "START" ) ) } ) } )
Discussion posts and replies are publicly visible
a!localVariables( local!addedCredit, local!balanceValue: a!refreshVariable( value: "" /*Put your balance calculation here*/, refreshOnVarChange: local!addedCredit ), /* ... ... ... . Your other code.. */ )
I do not see that you have used refresh variable anywhere in your code. You can do it as attached code.
It looks like you actually want to wrap local!user in a refreshVariable. Just using a!localVariables does not make a variable a refreshVariable. Similar to the example above, wrap local!user in a!refreshVariable and have local!user refresh on the change local!addedCredit.
local!user: a!refreshVariable(value: rule!AS_Get_Account(loggedInUser()), refreshOnVarChange: local!addedcredit),
still doesn't update
In the interface designer, you should be able to see the value of variables after each page evaluation. Also, can you share the code inside AS_Get_Account ?
a!localVariables( local!results: a!queryEntity( entity: cons!AS_DataStore_Account_Pointer, query: a!query( logicalExpression: a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "name", operator: "=", value: ri!user ) }, ignoreFiltersWithEmptyValues: true ), pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 50 ) ), fetchTotalCount: false ).data, cast( typeof('type!{urn:appian:as}AS_User_Account'()),local!results ) )
the values update, but only after I refresh the browser
You're running into a common local variable problem: https://docs.appian.com/suite/help/20.4/Local_Variables.html#using-local-variables-in-the-definition-of-refreshing-variables
Basically, your expression rule is querying the data once and then during each refresh on your interface, Appian isn't requerying the data it's just getting the cached value. If you wrap local!results in a!refreshVariable() and set refreshAlways to true, then the value will refresh in your interface.
Just updated it and it works fine, thank you so much