update record field doesn't work when i test my site and it works when i do the test in the interface

hello everyone , can anyone here help me please , i have develloped an interface and i configiured  the save button in this interface to do the update of a record field this is my code  :

a!buttonWidget(
          saveInto: {
            /*a!save(*/
              /*target: local!currentUserAccount,*/
              /*value: a!update(local!currentUserAccount , 'recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}PBY account.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}Solde', local!newBalance), */
            /*),*/
            a!writeRecords(
              records: local!currentUserAccount,
              onSuccess: a!save(
                target: local!currentUserAccount,
                value: a!update(local!currentUserAccount , 'recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}PBY account.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}Solde', local!newBalance), 
              ),
            )
          },
          label: if(ri!isUpdate, "Save", "Create"),
          submit: true,
          style: "SOLID",
          validate: true
        )
this code work and do the update if i do the test in the interface but when i test it in my interface using the record action " new Transaction " that shows me the interface that contain this botton . the didn't work ! how can solve the problem please 

  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    Hi,

    1. "that shows me the interface that contain this button . the didn't work " , This means the write to record is not happening?

  • if i do the test in the site  the write to record is not happening . but when i test it in the interface where i have the interface code the write to record happen

  • It means that if I want to have the "Solde" updated, I have to test the interface, not the site where I have the "create transaction" action, which is related to the interface.

  • 0
    Certified Senior Developer
    in reply to yassyass

    hi  is it throwing any error? Could you check the logs

  • Thanks for your answer. No, it doesn't show me any error. Just the "Solde" field in my record is not updated. The problem could be because I'm updating a local variable in my interface, so the update is only executed correctly when I test it on the interface page (where I have the code of this page) ??

    this is the code of my interface : 

    a!localVariables(
      local!currentUserAccount : rule!PBY_getaccountbyid("test"),
      local!newBalance : 
      if(
        and(
          a!isNotNullOrEmpty(
            ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme']
          ),
          a!isNotNullOrEmpty(
            local!currentUserAccount
          ),
          ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme'] >= 0
        ),
        local!currentUserAccount['recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}PBY account.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}Solde'] + ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme'],
        0
      ),
    
      local!typeValue: if(
        ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}TypeTransaction'] = "Virement interne",
        "Virement interne",
        if(
          ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}TypeTransaction'] = "Virement externe",
          "Virement externe",
          null()
        )
      ),
      a!formLayout(
        label: if(
          ri!isUpdate,
          "Update transaction",
          "Create transaction"
        ),
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!dropdownField(
                    choiceLabels: {"Virement interne","Virement externe",},
                    choiceValues: {"Virement interne","Virement externe",},
                    label: "Type transaction",
                    labelPosition: "ABOVE",
                    placeholder: "Selectionner le type de virement",
                    saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}TypeTransaction'],
                    value : local!typeValue,
                    searchDisplay: "AUTO",
                    validations: {}
                  ),
                  /*a!textField(*/
                  /*label: "Type Transaction",*/
                  /*labelPosition: "ABOVE",*/
                  /*value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}TypeTransaction'],*/
                  /*saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}TypeTransaction'],*/
                  /*characterLimit: 255,*/
                  /*required: false*/
                  /*),*/
                  a!integerField(
                    label: "Somme",
                    labelPosition: "ABOVE",
                    value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme'],
                    saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme'],
                    required: false
                  ),
                  a!textField(
                    label: "Discription",
                    labelPosition: "ABOVE",
                    value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{ab543c07-1cb7-49d8-84a7-f62d36e9b438}disc'],
                    saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{ab543c07-1cb7-49d8-84a7-f62d36e9b438}disc'],
                    characterLimit: 255,
                    required: false
                  )
                }
              ),
              a!columnLayout(
                contents: {
                  a!pickerFieldRecords(
                    label: "Compte Utilisateur",
                    labelPosition: "ABOVE",
                    placeholder: "Select a Account",
                    maxSelections: 1,
                    recordType: 'recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}PBY account',
                    value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{30901144-d5a7-4d96-8411-68ef7cef8a04}accountId'],
                    saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{30901144-d5a7-4d96-8411-68ef7cef8a04}accountId']
                  ),
                  a!dateTimeField(
                    label: "Date",
                    labelPosition: "ABOVE",
                    value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{2f45e501-55aa-4cda-907f-cd99cf82e7cc}date'],
                    saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{2f45e501-55aa-4cda-907f-cd99cf82e7cc}date'],
                    required: false
                  ),
                  /*a!pickerFieldRecords(*/
                  /*label: "",*/
                  /*labelPosition: "ABOVE",*/
                  /*placeholder: "Select a User",*/
                  /*maxSelections: 1,*/
                  /*recordType: 'recordType!{4fd8023a-5200-4bb0-af2d-7bed73fb330b}PBY user',*/
                  /*value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{692a0a51-d46d-4fee-a10e-aad2f90cb201}userId'],*/
                  /*saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}PBY transaction.fields.{692a0a51-d46d-4fee-a10e-aad2f90cb201}userId']*/
                  /*)*/
                }
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              saveInto: {
                /*a!save(*/
                  /*target: local!currentUserAccount,*/
                  /*value: a!update(local!currentUserAccount , 'recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}PBY account.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}Solde', local!newBalance), */
                /*),*/
                a!writeRecords(
                  records: local!currentUserAccount,
                  onSuccess: a!save(
                    target: local!currentUserAccount,
                    value: a!update(local!currentUserAccount , 'recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}PBY account.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}Solde', local!newBalance), 
                  ),
                )
              },
              label: if(ri!isUpdate, "Save", "Create"),
              submit: true,
              style: "SOLID",
              validate: true
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              value: true,
              saveInto: ri!cancel,
              submit: true,
              style: "OUTLINE",
              validate: false
            )
          }
        )
      )
    )

  • 0
    Certified Lead Developer
    in reply to yassyass

    I am not sure what you are trying to do. For a related record action to just modify some values, the normal way is, to create a form, submit it into a process and persist the data in the process instead of inside the form.

  • I do the configuration in the interface because I'm trying to update a field of another record, not the record that contains the form information.

  • 0
    Certified Lead Developer
    in reply to yassyass

    OK. Now, in line 114, you modify the data AFTER you write it to the DB. Is that by intention?

  • yes !  the field "solde" is initially given by the user in a account form then stored in a "account" record . if th user did a transaction then the field solde will be updated  

  • 0
    Certified Lead Developer
    in reply to yassyass

    Hm ... checking your code, I see that you write local!lcurrentUserAccount to DB, but do not do any updates to it. I mean, all saveInto in the form store their data into the rule input.