Skip to main content
yasminea4528
April 18, 2024
Solved

update record fieldd

  • April 18, 2024
  • 17 replies
  • 0 views

Hey everyone ! can anyone here help me , i have a record  named "compte" that contain a field named " solde"  and an other record named "transaction" that contian a field named "montant de transaction" i want that the solde field be updated awith the value " solde + transaction" how can i do this please  

( i tried this in the create or update transaction page and it gives me error :

a!buttonWidget(
saveInto: {
a!save(
target: ri!account['recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}projet account.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}Solde'],
value: (
ifnull(
if(
ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}projet transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme'] >= 0,
local!currentBalance + ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}projet transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme'],
local!currentBalance + ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}projet transaction.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}somme']
),
0
)
),
),
},
label: if(ri!isUpdate, "Save", "Create"),
submit: true,
style: "SOLID",
validate: true
)Â%A0

    Best answer by zacharyb8201

    a!buttonWidget(
      saveInto: {
        a!save(
          target: ri!account['recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}'],
          value: (
            if(
              and(
                a!isNotNullOrEmpty(
                  ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}']
                ),
                ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'] >= 0
              ),
              local!currentBalance + ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'],
              0
            ),
            
          ),
          
        ),
        
      },
      label: if(ri!isUpdate, "Save", "Create"),
      submit: true,
      style: "SOLID",
      validate: true
    )
    I think that is what you would want, it will check that that somme field in the transaction is not null and is greater than 0 if either of those are not true then it defaults the value to 0. Note you can change that 0 to be whatever the default value to be if the condition is not true. Also note this will update the record in memory but it will not automatically update the database to do that you will need to use a write records smart service.

    17 replies

    zacharyb8201
    April 18, 2024

    Is the above snippet resulting in an error? or is it just not giving the desired result?

    yasminea4528
    April 18, 2024

    this is the error : 

    zacharyb8201
    April 18, 2024

    a!buttonWidget(
      saveInto: {
        a!save(
          target: ri!account['recordType!{b37748b2-8103-41ea-8028-2b358e4f229c}.fields.{4a9de4b2-f127-44f1-86d2-21c2a6b2ee2d}'],
          value: (
            if(
              and(
                a!isNotNullOrEmpty(
                  ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}']
                ),
                ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'] >= 0
              ),
              local!currentBalance + ri!record['recordType!{ad2b45c4-cbc3-4de4-a189-c5593ad5032b}.fields.{e57ce205-d18d-4eb2-83ee-f669e5c56ab1}'],
              0
            ),
            
          ),
          
        ),
        
      },
      label: if(ri!isUpdate, "Save", "Create"),
      submit: true,
      style: "SOLID",
      validate: true
    )
    I think that is what you would want, it will check that that somme field in the transaction is not null and is greater than 0 if either of those are not true then it defaults the value to 0. Note you can change that 0 to be whatever the default value to be if the condition is not true. Also note this will update the record in memory but it will not automatically update the database to do that you will need to use a write records smart service.

    konduruc733182
    April 18, 2024

    Hello [mention:9322c334ce224857b6b7e2f011f055bd:e9ed411860ed4f2ba0265705b8793d05] 

    Have a null check for both the values before performing this calculation and if null use '0' as the default value and then perform the calculation and also make sure both the fields are of number type.