plus two fields in rowinserted event

i am using following line in rowinserted event :$vdisc1 = $rsnew[‘orderdetails_discount’] + $rsnew[‘unloading_discount’];both fields are float type. in version 2021, when we click add,
it is giving error :Notice: Undefined index: orderdetails_discount in C:\xampp\htdocs\pos2021\models\Si3detail.php on line 1718Notice: Undefined index: unloading_discount in C:\xampp\htdocs\pos2021\models\Si3detail.php on line 1718and did not saving the record

The fielld names do not exist in $rsnew. You may debug by checking the $rsnew, e.g.

var_dump($rsnew);
die();

this is the result of variable dump.array(12) { [“orderdetails_branchid”]=> string(1) “2” [“categories_barcode”]=> string(3) “101” [“orderdetails_qtyout”]=> string(1) “3” [“orderdetails_unitprice”]=> string(3) “685” [“orderdetails_discount”]=> string(1) “0” [“unloading_discount”]=> string(1) “0” [“orderdetails_sitotal”]=> string(1) “0” [“orderdetails_productcode”]=> string(3) “2-4” [“orderdetails_empid”]=> int(-1) [“orderdetails_entrydate”]=> string(19) “2020-12-20 09:23:30” [“orderdetails_headid”]=> int(13346) [“orderdetails_lineid”]=> int(18682) }the fields are available.

Did you have any code in another Server Events and/or Client Scripts that will hide those fields?

shahparzsoft wrote:

$vdisc1 = $rsnew[‘orderdetails_discount’] + $rsnew[‘unloading_discount’];
Notice: Undefined index: orderdetails_discount in C:\xampp\htdocs\pos2021\models\Si3detail.php on line 1718
Notice: Undefined index: unloading_discount in C:\xampp\htdocs\pos2021\models\Si3detail.php on line 1718
and did not saving the record

According to var_dump, the indexes do exist in $rsnew. You may double check if the characters in the field name in the database schema is same as what you use in the server event (e.g. they are all utf-8 characters). Moreover,

  1. Are you sure line 1718 is $vdisc1 = $rsnew[‘orderdetails_discount’] + $rsnew[‘unloading_discount’];?
  2. Row_Inserted event is fired after the row is inserted, it will not save your value $vdisc1 unless you save it yourself. If there is a field that you want to insert a value when adding a new record, you should use Row_Inserting server event, e.g.
    $rsnew[‘xxx’] = $vdisc1;