Page 1 of 1

After Insert Hook - Send Email Using Field Value NOT ID

Posted: 2018-07-31 18:02
by Ray Pierce
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;
}

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

Posted: 2018-07-31 19:08
by pbottcher
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){