Skip to main content
September 27, 2021
Question

Refresh issue variable after calling the WriteToDatastoreEntity service

  • September 27, 2021
  • 6 replies
  • 0 views

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"
    )
  }
)


Regards

6 replies

mikes0011
Brainy
September 27, 2021

What you have here seems essentially correct.  What do you have in "rule!CD_Count_CD_Test1()" though?

The Expression Guru
September 27, 2021

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

mikes0011
Brainy
September 27, 2021

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.

The Expression Guru