To make scripting easier, library script type is introduced in PLM. Today let's finish the Script Type topic by talking about it.
Library script is meant to contain utility functions that can be used in any other type of scripts just by importing it. So more reusing, less repeating. Let’s create an example of sending out email using library script:
Step 1: Create library script
Create a library script called EmailUtils with a function which can send email to the received recipients:
function sendEmailTo(recipients) {
var email = new Email();
email.subject = "Email subject";
email.body = "Email body. <br>Supporting HTML formatting.<br>";
email.to = recipients;
email.send();
}
Step 2: Import library script
Create an action script that imports the EmailUtils and call the “sendEmailTo” function. To import library script, just click the “plus” icon in the Imports field, and pick a library script from the list. Multiple libraries can be imported by repeating the action. Our action script “NotifyUsers” will generate a recipient list and feed it into the library function:
var myRecipients = "recipient1@mail.com, recipient2@mail.com";
sendEmailTo(myRecipients);
Step 3: Fire the action script
Fire the action script “NotifyUsers” as an on-create, on-edit, on-demand, workflow or scheduled script. Your choice!
The sent email will seems like this.
— Michal




Leave a Reply to Dmitry YemelyanovCancel reply