View all Blog posts
Uncategorized

Feature Friday: Taming Your Scripts in PLM 360

By     MARCH 28, 2014

7311992568_810efbe886_oUsing library scripts helps promote code re-use and make your scripts more manageable.  This lets you isolate functions that can be used in multiple scripts.

Today I want to share a really useful Library script that we use quite a bit in our PLM 360 tenant for email notifications.  The example I wrote this morning is quite simple, but you can check out the materials from AU 2013 class PL2758-P for some rich HTML email solutions.

Sending email is quite a common task used by many workflow scripts, so it makes sense to move it to a library script.  It’s pretty straightforward – contains functions for single email or to a list:

email_functions

And if want to copy and paste and put this in your tenant:

/*
functionality: sends email to multiple users
input   : sendTo{array}(string) – list of email addresses
        : subject(string) – subject for the email
return  : body(string)  – body for the email message
example :
        var sendTo = [];
        sendTo.push("michelle.stone@autodesk.com");
        var subject("this is a test");
        var body ("this is the body of the email");
        sendMultiEmails(sendTo, subject,body);
*/

function sendMultiEmails(sendTo, subject, body){
   
    for(var listItem in sendTo)
    {
        var email = new Email();
        email.to  = sendTo[listItem];
        email.subject = subject;
        email.body = body;  
        email.send();
    }
}

function sendMail(sendTo, subject, body){
        var email = new Email();
        email.to  = sendTo;
        email.subject =  subject;
        email.body = body;  
        email.send();
}

Here’s the example of a quick action script that will call it (I usually include a lot more fields of information, but this gets the point across!).  Notice I imported the library script for use. 

ff_action_script

And the resulting email I got:

email

You can call this action script on the first transition in the workflow and it will pull the email put in the record and send a notification to that address. 

Join us next week for PLM Talk Scripting Secrets where we’ll talk more about scripting!

–Michelle

Photo: Beth Scupham