Export To Email Blend Static Content with Dynamic Fields

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
studiobfd
User
Posts: 35

Export To Email Blend Static Content with Dynamic Fields

Post by studiobfd »

Hello,

I'm trying to customize an export to email thats currently using a "startup script" The subject, sender recipient are all working as it should, meaning its automatically populating as it should when clicking on the ""Export To Email". But what I'm hoping to do is add a static message, and mix it with two dynamically added fields see code below...

jQuery("#ewEmailForm textarea[name=message]").val("To Whom It May Concern,\n\nIf you have been scheduled for training for XXXXX the software portion of this install has been successfully completed, and is ready for your review. \n\nThe ABC Completion Checklist has been attached to this email, and this document contains the state of installation as of XXXXX. Please take the time to review and acknowledge this form with any questions you may have.\n\nPlease do not hesitate to contact me with any questions. \n\nMost Sincerely,\nABCInstall Team")

What I would like to do is pull the information from the "customer" field and the "Date" field from this view page and add the them dynamically to the message email field (Replacing the "XXXXX" placeholders in the above code)

Thank You Very Much


arbei
User
Posts: 9381

Post by arbei »

You can archive your goal in the Email_Sending Server Event instead of to do it in client side.

In the Email_Sending Server Event, you can build your email content and replace/append to the orignal email content.

Some data are passed to the server event as argument, if not, you can get it yourself.

For example:
$CustomerName = ew_ExecuteScalar("<SQL to get the customer name>");
$tday = ew_CurrentDate();

$MyContent = "To Whom It May Concern,\n\nIf you have been scheduled for training for " . $CustomerName . " the software portion of this install has been successfully completed, and is ready for your review. \n\nThe ABC Completion Checklist has been attached to this email, and this document contains the state of installation as of " . $tday . ". Please take the time to review and acknowledge this form with any questions you may have.\n\nPlease do not hesitate to contact me with any questions. \n\nMost Sincerely,\nABCInstall Team";

$Email->Body = $MyContent; //replace the content with your content.


studiobfd
User
Posts: 35

Post by studiobfd »

First, thank you for your knowledge its very helpful!

But can I use the Email_Sending Server Event to automatically fill the "Exportable Email Form"? I can see how to use this with "send email on add" etc but not on export. I need to email the results of a record either on "email export" or a button next to each record record in the view page.

Thanks So Much


arbei
User
Posts: 9381

Post by arbei »

Yes, you can also use the Email_Sending Server Event when export to email.

You can identify the correct action by $this->Export.

For example:

if ($this->Export == "email") {

// Code to build your content.

}


studiobfd
User
Posts: 35

Post by studiobfd »

Hello,

This is what I'm using now which works perfectly when "adding a record", but does not work when selecting "Export To Email" it does not automatically fill the email fields such as Snd, Subject to etc.

Thank You Once again for your assistance.


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

  if ($this->Export == "email") {

$Email->Recipient = $Args["rsnew"]["XYZEMAIL"];
$CustomerName = $Args["rsnew"]["CUSTOMER"];
$tday = ew_CurrentDate();
$Signature = $Args["rsnew"]["XYZENGINEER"];
$PrinterType = $Args["rsnew"]["XYZTYPE"];

//$SubjectLineMessage = "SOFTWARE INSTALL COMPLETION - " . $CustomerName . " - " . $XYZType . "";

$Email->Subject = $SubjectLineMessage;

$MyContent = "To Whom It May Concern,\n\nIf you have been scheduled for training for " . $CustomerName . " the software portion of this install has been successfully completed, and is ready for your review. \n\nThe ABC Completion Checklist has been attached to this email, and this document contains the state of installation as of " . $tday . ". Please take the time to review and acknowledge this form with any questions you may have.\n\nPlease do not hesitate to contact me with any questions. \n\nMost Sincerely,\n " . $Signature . "";

$Email->Body = $MyContent;
}
return TRUE;
}



studiobfd
User
Posts: 35

Post by studiobfd »

Hello,

  1. When you go the the list page you have "Export to XML, CSV, PDF, EMAIL"
  2. Click on "Email"
  3. Email Model window opens
  4. All fields "To, Cc, Bcc, Subject and Message Body are all empty (blank) Send Button

I want all these fields to be filled in automatically with the code I have attached. Right now they are all BLANK so I cannot even click the send button.

If you have a better way of sending the "export email" I am open to any suggestions or recommendations you may have.

Thanks Again!


arbei
User
Posts: 9381

Post by arbei »

Assuming you are trying to export the View page information as email. You can simply pass the email and signature from the server side to the client side script by PHP echo.

And on the Startup Script of add page, subscribe the click event of the "Export to Email" button and fill in the form value.

For example:

    var remail = "<?php echo $receiver; ?>"; // escape double quotes if necessary
    var signature = "<?php echo $signature; ?>";  // escape double quotes if necessary
    var message = "<Your static message>";  // escape double quotes if necessary

// write your code to manipulate the variable message
// ....
$(".ewEmail").click(function(){
$frm = $("#ewEmailForm")
$frm.find("#recipient").val(remail);
$frm.find("#message").val(message);
});

Read help file topic: "Server Events and Client Scripts" -> "Startup Scripts" for more information.


hosthere
User
Posts: 4

Post by hosthere »

Thanks for the insight studiobfg.

I just couldn't get the assignment to the "Export to Email" button to work. Ended up modifying the code as follows and having to put it in the global startup script;

var remail = "<?php echo $receiver; ?>"; // escape double quotes if necessary
var signature = "<?php echo $signature; ?>"; // escape double quotes if necessary
var message = "<Your static message>"; // escape double quotes if necessary
// write your code to manipulate the variable message
// ....
//$(".ewEmail").click(function(){
$frm = $("#ewEmailForm")
$frm.find("#recipient").val(remail);
$frm.find("#message").val(message);
//});

Any further advice on how to assign to the export button?

I am using phpMaker v11.


hosthere
User
Posts: 4

Post by hosthere »

Had another go and got it to work using the following, including putting it in the page startup script rather than global;

...
$("#emf_timesheets").click(function(){
...

#emf_timesheets is the button id in my case.


studiobfd
User
Posts: 35

Post by studiobfd »

Hi hosthere,

I'm in the same boat. Stepped away from it for a bit clear my head.


Post Reply