After Insert Hook - Send Email Using Field Value NOT ID

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
Ray Pierce
Posts: 3
Joined: 2018-01-04 18:35

After Insert Hook - Send Email Using Field Value NOT ID

Post by Ray Pierce » 2018-07-31 18:02

I am using the after_insert hook to send a notification email to organization members when there is a new first aid record created. The cde I'm using is what I copied from the tutorial on this hook (below). The issue I'm having is that the email sends the ID numeric value which is useless to the reader. I want to instead use the actual project name (we're a construction company) that the ID number refers to in the project table. I am not a coder so if you can help, please give me clear instruction of where I need to make changes if it can even be done. Thank you in advance!


///// Here is the code I'm currently using /////

function firstaid_after_insert($data, $memberInfo, &$args){
/ to compose a message containing the submitted data,
// we need to iterate through the $data array
foreach($data as $field => $value){
$messageData .= "$field: $value \n";
}

@mail(
// mail recipient
"[email protected]",

// subject
"A FIRST AID report has been submitted",

// message
"The following FIRST AID REPORT was submitted by {$memberInfo['username']} This is raw data from the report, share it with crews.: \n\n".
$messageData,

// sender address
"From: [email protected]"
);

//end email code


return TRUE;
}

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

Re: After Insert Hook - Send Email Using Field Value NOT ID

Post by pbottcher » 2018-07-31 19:08

Hi,

please replace

Code: Select all

foreach($data as $field => $value){

by

Code: Select all

		$value_data = get_joined_record('firstaid',$data['selectedID'],true);
		foreach($value_data as $field => $value){
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.

Post Reply