Send email on status change

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Send email on status change

Post by aarlauskas » 2020-10-30 20:48

Hi, I’m using the below code on most of my little project to send an email when the checkbox is ticked. I have a Status field (dropdown, not lookup) with two option: Complete;;Incomplete. I want to send an email when option ‘Complete’ is selected in the Status field instead of using checkbox method. Could someone possibly help me to change the below code to achieve this? Presuming the table name is ‘my_table_name’ with field ‘report_status’ that has options: Complete;;Incomplete . Thank You

Code: Select all

// ******** Send email if checkbox is checked *********

	$recipient = $data['email'];
	$CC = "";
	$sendemail = sqlValue("select emailadvice from my_table_name where id='{$data['selectedID']}'");
	$userEmail = sqlValue("select email from membership_users where memberID='".getLoggedMemberID()."'");
	if ($sendemail != 0) {

		$resetMail = @mail(
			// To
			"$recipient, $userEmail",

			// Subject
			"Incident Report Submitted by {$memberInfo['custom'][0]}",

			// Content

			"Incident Report Submitted by {$memberInfo['custom'][0]}. \n" .
			" \n" .
			"For full report details please go to XXXXXXX and select record number: {$data['id']}. \n" .

				"================================================ \n" .
				"DO NOT REPLY TO THIS EMAIL. This report is generated by XXXXX",

			// From
			"From: [email protected]"
		);
		// then update the send email checkbox back to default of 0
		if (resetMail) {
			sql("update my_table_name set emailadvice=0 where id='{$data['selectedID']}'", $abc);
		}
	}
	// ******** End send email if checkbox is checked *******

		return TRUE;
	}

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

Re: Send email on status change

Post by pbottcher » 2020-10-30 21:43

Hi,

just retrieve the status field instead of the emailadvice .

then use e.g.

Code: Select all

If ($sendmail == 'Complete')
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.

User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Send email on status change

Post by aarlauskas » 2020-10-31 08:22

Hi, doesn't seem to work this way, unless I'm missing something. Any chance you could copy/paste my complete code here with the change that you think should work? Thanks

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

Re: Send email on status change

Post by pbottcher » 2020-10-31 15:30

Can you post the code you tried?
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.

User avatar
aarlauskas
Veteran Member
Posts: 127
Joined: 2019-04-28 18:03
Location: Medway, UK

Re: Send email on status change

Post by aarlauskas » 2020-10-31 19:39

Ok I found the error, small typo in your line. I was copying your line as you sent 'If ($sendmail == 'Complete')' . but just noticed in your line you put $sendmail instead of $sendemail. Great Success man :D All working, Thank You!

Post Reply