GSI Website Blog 2023

Custom Alerts

Written by stbadmin | Jul 17, 2018 4:00:00 AM

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:

  1. Create a new Form Script (in this example, Expense Report)
  2. OpenAir defaults a basic function for you to use in the Scripting Editor:
  3. We will remove “type” as it does not apply here. Insert your variables to build the conditions for the alert:
  4. Insert the conditions to send the alert:
  5. Define the message using a variable:
    1. Note: you can use “+var” [where “var” is the defined variable] to append variables to the body. For example, the body line could read:
      1. “Alert: Someone named” +username +”expensed a personal item.”,
    2. Call the NSOA.meta function to send the alert in the function:
    3. Your final script should look like this:

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);   

    }

   

}

  1. 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)
  2. Deploy your script and if the criteria matches your conditions:
  3. You should receive an email: