Refresh issue variable after calling the WriteToDatastoreEntity service

Certified Senior Developer

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

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

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

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    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
    

  • +1
    Certified Lead Developer
    in reply to cedric01

    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.

Reply
  • +1
    Certified Lead Developer
    in reply to cedric01

    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.

Children