Add username and department to subject line

Currently, I get an update email saying this:

PX_2020 record(s) updated

Record status changed as follows:
Table: PX_2020
Key value: 226
Action: Updated

How can I get the subject line to read:

PX_2020 record(s) updated by John_Smith of Marketing
(John_Smith is his username, Marketing is his department)

Record status changed as follows:
Table: PX_2020
Key value: 226
Action: Updated

Put this code into “Email_Sending” server event that belongs to the “PX_2020” table:

if (CurrentPageID() == “edit”) { // If Edit page
$email->Subject = "PX_2020 record(s) updated by " . $args[“rsnew”][“username”]; . " of " . $args[“rsnew”][“department”]; // Change subject, assume “username” and “department” fields exists in the current table
}

This code is in that section:

Do I replace this code that is in there, or where should I put that code:

// Email Sending event
function Email_Sending($email, &$args) {
//var_dump($email); var_dump($args); exit();
return TRUE;
}

Do I replace this code that is in there, or where should I put that code

if (CurrentPageID() == “edit”) { // If Edit page
$email->Subject = "PX_2020 record(s) updated by " . $args[“rsnew”][“username”]; . " of " . $args[“rsnew”][“department”]; ; // Change subject, assume “username” and “department” fields exists in the current table
}

// Email Sending event
function Email_Sending($email, &$args) {
//var_dump($email); var_dump($args); exit();

if (CurrentPageID() == “edit”) { // If Edit page
$email->Subject = "PX_2020 record(s) updated by " . $args[“rsnew”][“username”]; . " of " . $args[“rsnew”][“department”]; // Change subject, assume “username” and “department” fields exists in the current table
}

return TRUE;
}

When I put in this code the site will not load, when I replace it with the original it works.

This is the original, where do the pieces from the Body text come from Args? I just don’t understand.

What is the meaning of each piece of the code below?

// Email Sending event
function Email_Sending($email, &$args) {
//var_dump($email); var_dump($args); exit();
return TRUE;
}

nets this in an email:

SUBJECT:
PX_2020 record(s) updated

BODY:
Record status changed as follows:
Table: PX_2020
Key value: 14
Action: Updated


From the suggested code what does each piece do?

$email->Subject = "PX_2020 record(s) updated by " . $args[“rsnew”][“username”]; . " of " . $args[“rsnew”][“department”];

mw4 wrote:

What is the meaning of each piece of the code below?

That is a server event that you can use to change the default content/subject/recipient of the email if you enable one/some options under “Table” setup → “Email Notification”.

When I put in this code below into Server Events >> Table Specific >> Common >> Email_sending
The site will not load and gives an HTTP ERROR 500

PX_2020 is the table
Department and username are fields in that table


// Email Sending event
function Email_Sending($email, &$args) {
//var_dump($email); var_dump($args); exit();

if (CurrentPageID() == “edit”) { // If Edit page
$email->Subject = "PX_2020 record(s) updated by " . $args[“rsnew”][“username”]; . " of " . $args[“rsnew”][“department”]; // Change subject, assume “username” and “department” fields exists in the current table
}

return TRUE;
}


mw4 wrote:

$email->Subject = "PX_2020 record(s) updated by " . $args[“rsnew”][“username”]; . " of " . $args[“rsnew”][“department”]; // Change subject, assume “username” and “department” fields exists in the current table

You have extra “;”. During development you better enable error in php.ini, see:

Got the fix with the two ;;


Now the body of the email reads:

Record status changed as follows:
Table: Px_2020
Key value: 6012
Action: Updated

What is the syntax to change that body part…I the code below and I still got just this

Record status changed as follows:
Table: Px_2020
Key value: 6012
Action: Updated

// Email Sending event
function Email_Sending($email, &$args) {
//var_dump($email); var_dump($args); exit();

if (CurrentPageID() == “edit”) { // If Edit page
$email->Subject = “Px record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“Tm_2020”] . " Updated”;
$Email->body = “Px record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“Tm_2020”] . " Updated” ;
}

return TRUE;
}


And also hoe can I use Currentuser() in the above?

mw4 wrote:

$email->Subject = “Px record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“Tm_2020”] . " Updated”;
$Email->body = “Px record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“Tm_2020”] . " Updated” ;

You have wrong letter case ($Email).

I fixed the E vs e

Still the same … All it outputs in the body is this which is standard:

Record status changed as follows:
Table: Px_2020
Key value: 6012
Action: Updated

Total actual code:

// Email Sending event
function Email_Sending($email, &$args) {
if (CurrentPageID() == “edit”) { // If Edit page
$email->Subject = “Px record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“T_2020”] . " Updated”;
$email->body = “Px record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“T_2020”] . " Updated” ;
}
return TRUE;
}

The subject part works perfectly

The subject part works perfectly

Where is the standard current email body edited/changed?

Record status changed as follows:
Table: xxxxx
Key value: xxxx
Action: Updated

mw4 wrote:

$email->body = “Px record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“T_2020”] . " Updated” ;

You still have wrong letter case (“body”).

For email content, you may read the topic Multi-Language Project → Sending Email in Multi-Language in the help file.

Ok, that worked…Awesome

Now–how can I add CurrentUser, and the field that was updated to that Body?

You may just build your own content and set it to the Body property, for example, you can use CurrentUserName() to get the user name.

What’s the syntax for capturing what field was changed?

You may compare $args[“rsold”] and $args[“rsnew”], see also: https://www.php.net/manual/en/function.array-diff.php.

Ok, I have this working but for some reason, a couple of fields are not populating:

// Email Sending event
function Email_Sending($email, &$args) {
//var_dump($email); var_dump($args); exit();

if (CurrentPageID() == “edit”) { // If Edit page
$email->Subject = “Player record of " . $args[“rsnew”][“FirstLast”] . " on " . $args[“rsnew”][“Email”] . " on " . $args[“rsnew”][“Phone”] . " Updated” ;
$email->Body = "Player record of " . $args[“rsnew”][“FirstLast”] . $args[“rsnew”][“Team_2020”] . $args[“rsnew”][“TeamID”] . " Updated by: " . CurrentUserName() ;
}
return TRUE;
}

Everything shows up correctly except $args[“rsnew”][“Team_2020”] . $args[“rsnew”][“TeamID”]

is there something that I am missing? these are all in the same record and the fields are listed in their correct case. Is it possible that the underscore in Team_2020 is messing it up?

mw4 wrote:

Everything shows up correctly except $args[“rsnew”][“Team_2020”] . $args[“rsnew”][“TeamID”]

Try to use rsold instead of rsnew.