Hello devs, I need your help. I have two records: 'account' and 'transaction', and the 'balance' field of 'account' varies based on the value of the 'Amount' field of 'Transaction'. I've added conditions to update the 'Balance' (in the saveInto function) when the user clicks 'Create transaction' and it works well in the interface the field in my ruleInput record has been updated, but the update isn't happening at the database level. How can I dynamically change the balance on my site based on the value of the 'Amount' field of the transaction record?
Discussion posts and replies are publicly visible
In saveInto, update the real account, not rule!Input. Use queryRecord to get from Account record(transaction.accountId) to fetch it. Calculate new balance based on transaction type and amount. Simply update the account's Balance with update(account, Balance, newBalance). Save the transaction record as usual.Let me know if that works for you.
the "Account" record shouldn't be passed to my interface as a ri ?
Check below code.
a!localVariables( local!currentUserAccount : rule!PBY_getaccountbyid("test"), local!newBalance : if( and( a!isNotNullOrEmpty( ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'] ), a!isNotNullOrEmpty( local!currentUserAccount ), ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'] >= 0 ), local!currentUserAccount + ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'], 0 ), local!typeValue: if( ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}'] = "Virement interne", "Virement interne", if( ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}'] = "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}.fields.{7c7b6fd3-57be-4b83-8c0e-4e9ac46f0ed3}'], 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}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'], saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'], required: false ), a!textField( label: "Discription", labelPosition: "ABOVE", value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{ab543c07-1cb7-49d8-84a7-f62d36e9b438}'], saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{ab543c07-1cb7-49d8-84a7-f62d36e9b438}'], 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}', value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{30901144-d5a7-4d96-8411-68ef7cef8a04}'], saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{30901144-d5a7-4d96-8411-68ef7cef8a04}'] ), a!dateTimeField( label: "Date", labelPosition: "ABOVE", value: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{2f45e501-55aa-4cda-907f-cd99cf82e7cc}'], saveInto: ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{2f45e501-55aa-4cda-907f-cd99cf82e7cc}'], 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}.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}', 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 ) } ) ) )
It gives me this error : Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error [evaluation ID = 60b37:5d843] : An error occurred while executing a save: Expression evaluation error: You must specify a variable to save into, such as ri!name << fn!sum. Received: b37748b2-8103-41ea-8028-2b358e4f229c.
You need to use a!save() inside a saveInto to manipulate data.
Thank you ! it works when i test the interface but not in the dataBase and the record
Perfect! Happy to hear that yassyass
thank you ! But i want the data to be updated in my record base too
So that the "solde" displayed in my interface is the correct solde after creating a transaction
yassyass I would advice you to go through this documentation.https://docs.appian.com/suite/help/24.1/recipe-use-the-write-records-smart-service-function-on-an-interface.html#:~:text=trigger%20the%20a!-,writeRecords()%20smart%20service%20function.,application%2C%20click%20NEW%20%3E%20Interface.You have several ways of doing this but I would suggest you to use writeRecord().
thanks alot for your help yes i use writeRecord() but it update the field only if i test it in the interface , if i do the test in my site the update is not working
That shouldn't happen. Check your code properly.