Attaching Custom Content Files to an Email

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!

Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

Building and sending attachments with custom content is a very common customization achieved via custom scripting. To learn how to build a PDF file with custom content see our PDF Functions.

Once you've built your custom content the are two options to send this out via email.

1. Using sgapiEmailSend you can populate each of the fields for an email including %%attachments to attach your custom files. This will send an email with your attachments when the script is run.

%%pdf = "Example PDF";
%%text = "Text to include in PDF";
%%size = 14;
%%options = array('spacing' => 1.5);
%%table = array( array(1,2,3,4), array(5,6,7,8), array (9,10,11,12) );
%%columns = array('Column A','Column B','Column C','Column D');

sgapiNewPDF(%%pdf,'letter','portrait');
sgapiSetFontPDF(%%pdf,'courier');
sgapiSetColorPDF(%%pdf,0,0,0);
sgapiImagePDF(%%pdf,"https://surveygizmolibrary.s3.amazonaws.com/library/160589/surveysoftwareapi.png"); 
sgapiTextPDF(%%pdf,%%text,%%size,%%options);
sgapiTablePDF(%%pdf,%%table,%%columns,'Table Title');

%%formattedpdf = sgapiPDFOutput(%%pdf);

%%attachment['example.pdf'] = %%formattedpdf;

%%to = sgapiGetValue(7);
%%toName = sgapiGetValue(1);
%%textBody = '';
%%bcc = '';
%%htmlBody = "Thank you for completing the survey. Your response is appreciated<br />We will be in touch shortly!.<br /><br /> Thanks,<br />Your Company";

sgapiEmailSend(%%to, %%toname, "Your Company", "your.company@company.com", "Your Assessment Results", %%textBody, %%htmlBody, %%bcc, %%to, "html", %%attachment);

2. A much easier way to achieve this is to use the "email_attachment" parameter for the sgapiSetQuestionProperty function to attach your custom built file to an existing send email action. The script for this looks like so:

%%pdf = "Example PDF";
%%text = "Text to include in PDF";
%%size = 14;
%%options = array('spacing' => 1.5);
%%table = array( array(1,2,3,4), array(5,6,7,8), array (9,10,11,12) );
%%columns = array('Column A','Column B','Column C','Column D');

sgapiNewPDF(%%pdf,'letter','portrait');
sgapiSetFontPDF(%%pdf,'courier');
sgapiSetColorPDF(%%pdf,0,0,0);
sgapiImagePDF(%%pdf,"https://surveygizmolibrary.s3.amazonaws.com/library/160589/surveysoftwareapi.png"); 
sgapiTextPDF(%%pdf,%%text,%%size,%%options);
sgapiTablePDF(%%pdf,%%table,%%columns,'Table Title');

%%formattedpdf = sgapiPDFOutput(%%pdf);

%%attachment['example.pdf'] = %%formattedpdf;

//Attach to existing send email action (ID 3)
sgapiSetQuestionProperty(3,"email_attachments",%%attachment);

Scripting and Other Custom Solutions

We’re always happy to help you debug any documented script that is used as is. That said, we do not have the resources to write scripts on demand or to debug a customized script.

If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for SurveyGizmo features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!