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
  • 0
    Certified Lead Developer

    You will need to change line 14. The valueToStore cannot just be your new phone number. How should Appian know which field that is or which row in DB to update?

    You either already have a local variable containing that selected user CDT or you need to query it from DB. Then, update that specific field in that CDT, and finally, write it to DB.

Reply
  • 0
    Certified Lead Developer

    You will need to change line 14. The valueToStore cannot just be your new phone number. How should Appian know which field that is or which row in DB to update?

    You either already have a local variable containing that selected user CDT or you need to query it from DB. Then, update that specific field in that CDT, and finally, write it to DB.

Children