Change a value in DB using writeToDataStoreEntity

Hi everyone, 

I'm having a question regarding how to use the writeToDataStoreEntity function to modify values in DB. 

To be specific, I'm having a form that allow users to update their phone numbers. It will be saved in a DB with corresponding DSE storing all customer data. When the customer click  the button Save New Change, the existing number need to be replaced by the new number, both on the interface and in the DB. I'm not sure how to do that yet. I'm thinking of using writeToDataStoreEntity, and find the number that needs to change by the unique customer ID, but not really know in specific how. 

Any one have a solution for this? Really appreciate your help!

Code for the Save New Change button is currently as below, in that local!allUser query list of users from db, and selected user is the one that need to change phone number:

This code shows an error:  An error occurred while trying to convert the given data to the type of the specified entity "ALL_USERS" [id=f4ece61e-8fb0-4abd-a39b-8096f1aaf650@32783, type=ALL_USERS (id=6306)] (data store: AUS Data Store). Value that could not be converted: ActivityClassParameter[name=DynamicInputs,it=3,v=new name] Details: Could not cast from Text to ALL_USERS. Details: CastInvalid (APNX-1-4400-000)

a!localVariable(
local!saveNewChange:false,
a!sideBySideItem(
          item: a!richTextDisplayField(
            labelPosition: "COLLAPSED",
            value: {
              a!richTextIcon(
                icon: "save",
                link: a!dynamicLink(
                  saveInto: {
                    a!save(
                    a!writeToDataStoreEntity(
                      dataStoreEntity: cons!DSE_All_USERS,
                      valueToStore: local!newNumber,
                      onSuccess: {
                      a!save(local!saveNewChange, false),
                      a!save(local!newNumber, null),
                      a!save(
                        tostring(index(local!allUsers,local!selectedUser.id,"phoneNumber",null)),tostring(fv!storedValues)
                      )
                      },
                ),
                linkStyle: "STANDALONE",
                size: "STANDARD",
                caption: "Save New Change"
              )
            }
          ),
          width: "MINIMIZE",
          showWhen: a!isNullOrEmpty(local!newNumber)
        ),

  Discussion posts and replies are publicly visible

Parents Reply Children
  • I was able to update data on the DB, and then query it back to the interface using queryRecordType as you suggested! Thanks a lot. 

    There is just one issue left is that when I changed the data and click button Save, the data shown on the interfase are not real time, I need to refresh the interface for the new phone number to show up eventhough refreshAlways = true in a!queryRecordType. Do you know what is the possible reason?