Page 1 of 1

After Update Function not working

Posted: 2022-02-11 14:08
by xbox2007
hello ,
i have AppGini 22.11

i try use After Update Function to insert value to one field , field name (Available).

Code: Select all

function S_Item_Request_after_update($data, $memberInfo, &$args) {
		
		$Sub_ID	= $data["R_Sub_item"];
			
		$Avail  = sqlValue("SELECT Available FROM  Sub_Items  WHERE Id ='{$Sub_ID}'");  
		
		$data['Available'] = $Avail;
		
		
		//echo $Avail;
		//exit;
		return TRUE;
	}
i can find value of $Avail; if i use

Code: Select all

		echo $Avail;
		exit;
i try same with after insert but also not working

i know i can update value of my field using update Query

but why After Update Function not working !!!!

Re: After Update Function not working

Posted: 2022-02-11 14:42
by pbottcher
Hi,

the AFTER function(s) works (as the name says) after the update to the record has taken place. So the $data provides you with the values of the record AFTER THE UPDATE. If you want to do any more changes you need to use the SQL statement to do so.

Re: After Update Function not working

Posted: 2022-02-13 05:30
by xbox2007
thanks for your replay .
i try like this not work : (this before insert)

Code: Select all

function tablename_before_insert(&$data, $memberInfo, &$args){
 
    $data['total'] = $data['quantity'] * $data['unit_price'];
 
    return true;
}
also i try like this also not working :

Code: Select all

function tablename_before_update(&$data, $memberInfo, &$args){
     
    // calculate total after applying discount
    $data['total'] = $data['subtotal'] * (1 - $data['discount'] / 100);
     
    // calculate total after applying sales tax 
    $data['total'] = $data['total'] * (1 + $data['sales_tax'] / 100); 
     
    return true;
}
https://bigprof.com/appgini/help/advanc ... name_init

Re: After Update Function not working

Posted: 2022-02-13 08:28
by pbottcher
What are the field settings in your project. If you have set the field to "not display" or "readonly" in the detail view. The $data array does not handle them and you need to take care of those fields on your own.

You can use:

Code: Select all

echo "<pre>";var_dump($data);exit
before you do the calculation to see if the $data['total'] is available. If not you need to use SQL to handle that case.

Re: After Update Function not working

Posted: 2022-02-24 14:43
by xbox2007
Thanks pböttcher for your replay

in my project field is display and not not read only

thanks