After Update Function not working

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
xbox2007
Veteran Member
Posts: 152
Joined: 2016-12-16 16:49

After Update Function not working

Post by xbox2007 » 2022-02-11 14:08

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 !!!!

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1709
Joined: 2018-04-01 10:12

Re: After Update Function not working

Post by pbottcher » 2022-02-11 14:42

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 152
Joined: 2016-12-16 16:49

Re: After Update Function not working

Post by xbox2007 » 2022-02-13 05:30

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1709
Joined: 2018-04-01 10:12

Re: After Update Function not working

Post by pbottcher » 2022-02-13 08:28

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.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 152
Joined: 2016-12-16 16:49

Re: After Update Function not working

Post by xbox2007 » 2022-02-24 14:43

Thanks pböttcher for your replay

in my project field is display and not not read only

thanks

Post Reply