Lua Scripting Resources

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language.


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. Read-only scripts will continue to function; you will just be prevented from editing. The exact date on this is to be determined; we will send notifications well ahead of time.


 Go to our Legacy Scripting Documentation.

While SurveyGizmo is one of the most flexible survey tools around, we get requests for customizations that are not available out of the box. This is where JavaScript and Custom Scripting can save the day. If you have scripting chops you can use the JavaScript action or the Custom Scripting action to achieve the survey of your dreams.


[article("bodfy")]

This script allows you to create a certificate to email to survey/quiz respondents. 

See the script in action in an example survey!

OR

Add a survey with this script and setup to your account!

Estimated implementation and testing time: 30-60 minutes (Note: This time estimate does not include the time required to create a certificate for your business or organization.)

Features and functions used in this script:

The Script and Setup

Create a quiz, form, or survey. The script includes the answers to 3 questions on the certificate; name, course, and date. You can use these same fields, or create your own.

After creating your own certificate image, upload the image to your Alchemer file library. 

Then, copy the below script and paste it into a Custom Script Action that follows the survey questions that are being used in the script. Below, we cover how to customize the script to create your own custom certificate. 

name = getvalue(3)
course = getvaluelabel(4)
date = getvalue(5)

pdftemplate = [[<head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /></head>
<style>
.name
{width:100%;
top: 290px;
display: block;
position: absolute;
font-size: 30pt;
text-align:center;
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
color: #000000;}
.course
{width:100%;
top: 420px;
display: block;
position: absolute;
font-size: 20pt;
text-align:center;
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
color: #000000;}
.date
{width:100%;
top: 510px;
display: block;
position: absolute;
font-size: 20pt;
text-align:center;
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
color: #000000;}
</style>
<body style="margin:0; padding=0;">
<img src="http://surveygizmolibrary.s3.amazonaws.com/library/160589/BlankCertificate.png" style="height:770px; width:1097px;">]]
..'<span class="name">'..name..'</span>'
..'<span class="course">'..course..'</span>'
..'<span class="date">'..date..'</span></body>'

pdf = htmltopdf(pdftemplate,true,false)

attachment = {}
attachment['certificate.pdf'] = pdf

htmlBody = [[<b>Congratulations!</b><br/><br/>
You have completed the requirements for this training.<br/><br/>
Your personalized certificate is attached to this email.<br/><br/>
Domo arigato,<br/><br/><b>Mr. Roboto</b><br/>Styx Robotics</br>]]

textbody = [[Congratulations! 
You have completed the requirements for this training. 
Your personalized certificate is attached to this email.
Domo arigato, Mr. Roboto
Styx Robotics]]

to = getvalue(6)
toName = getvalue(3)
from = "noreply@sgizmo.com"
fromName = "Mr. Roboto"
subject = "Certificate of Completion"
bcc = "notifications@sgizmo.com"
mailReplyTo = "noreply@sgizmo.com"
type = 'HTML'


emailsend(to, toName, from, fromName, subject, textBody, htmlBody, bcc, mailReplyTo, type, attachment)

Required Customizations

In the script above you will need to customize variables highlighted in yellow in order to make the script work in your survey.

Update the variables as follows:

name - This variable will indicate the question ID of the field for the name.

course - This variable will indicate the question ID of the field for the course.

date - This variable will indicate the question ID of the target Checkbox question.

pdftemplate - There are several aspects of the pdf template you can change. 

The emailsend function has 11 parameters. All 11 parameters are required. You can personalize these as you need. Note: If you change the variable name you must change the variable name in the emailsend function.

to - The recipient's email address. In this script, this is set up as a variable that pulls from the email address question in the survey. Change this questionID to the question in your survey where this is gathered.

toName - The recipient's name. In this script, this is set up as a variable that pulls from the name question in the survey. Change this questionID to the question in your survey where this is gathered.

from - The sender's email address.

fromName - The sender's name.

subject - The subject line.

textBody - The plain text email body.

htmlBody - The HTML formatted email body.

bcc - bcc email address (can be an array).

mailReplyTo - Send replies to email address.

type - The type of email to send "text" or "html."

attachments - Email attachments (can be an array).