Custom Alerts
Jimmy Morales, Consultant
Question: Alerts and Notifications are limited in OpenAir; what if I want emails different than what OpenAir offers by default?
Answer: You can leverage OpenAir scripting to create custom emails for virtually anything in OpenAir!
Using the Scripting Reference Card available on OpenAir.com, you can build custom scripts that allow you to send up to 3 different emails in a form, or 100 scheduled emails with 30,000 characters each.
Creating a basic email alert through scripting is easy:
- Create a new Form Script (in this example, Expense Report)
- OpenAir defaults a basic function for you to use in the Scripting Editor:
- We will remove “type” as it does not apply here. Insert your variables to build the conditions for the alert:
- Insert the conditions to send the alert:
- Define the message using a variable:
- Note: you can use “+var” [where “var” is the defined variable] to append variables to the body. For example, the body line could read:
- “Alert: Someone named” +username +”expensed a personal item.”,
- Call the NSOA.meta function to send the alert in the function:
- Your final script should look like this:
- Note: you can use “+var” [where “var” is the defined variable] to append variables to the body. For example, the body line could read:
function main() { var notes = NSOA.form.getValue(‘notes’);
if (notes == 'Just for fun!'){
var msg = { to: ["myaddress@example.com"], cc: [], bcc: ["external@example.com"], subject: "ALERT: Someone expensed a personal item.", body: "Hello, a user has expensed a personal item.", author: 37 };
NSOA.meta.sendMail(msg); }
} |
- After you define which function to execute and under what circumstance (In this example: After clicking “Save” on an Expense Report, but just before the form is saved, Execute the function called main)
- Deploy your script and if the criteria matches your conditions:
- You should receive an email: