Skip to main content
October 3, 2021
Solved

refreshVariables

  • October 3, 2021
  • 9 replies
  • 0 views

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"
                          ),
                          "Â%A0",
                          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"
                          ),
                          "Â%A0",
                          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"
                      )
                    )
                  }
                )
              }
            )

    Best answer by danny.verb

    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.

    9 replies

    ravir0002
    October 4, 2021

     

    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.

    October 4, 2021

    It doesn't work

    October 4, 2021

    Should I have used a process model instead of a a!writetodatabase?