A company requires that whenever the highest priority level
is assigned to an asset, then an email is sent to the asset custodian.
An automation script is created to send this email. The automation
script uses a choice message to confirm that the email should be sent.
About this task
The example launch point and automation script that implement a choice message and its
processing use the Jython programming language.
Procedure
- In the Database Configuration application, click Messages and
create a new message with the following values:
Fields |
Values |
Message Group |
asset |
Message Key |
assetpriorityemail |
Display Method |
MSGBOX |
Message ID Prefix |
BMXZZ |
Message ID Suffix |
W |
Display ID |
1 |
Value |
Asset custodian can be notified through email when priority {0} is set. Send
email? |
Buttons |
Select Yes and No buttons.
|
- Click OK.
- Go to the Automation Scripts application by clicking .
- In the Automation Scripts application, click
.
- In step 1, specify the launch point name and select the asset object and the priority
attribute.
- In the Events section, select Run action.
- Click Next.
- In step 2, specify the script name and set the log level to debug.
- Click Next.
- In step 3, paste in the following source code and then click
Create:
# Business logic implementation if user selects Yes choice (clicks Yes button)
def yes ():
service.log("Sending Email")
# Business logic implementation if user selects No choice (clicks No button)
def no ():
service.log("Not Sending Email")
# Business logic to present the choice message initially
def dflt ():
params=[str(priority)]
service.log("Throw ERROR")
# Use the service utility's yncerror() method to push the choice message
service.yncerror("asset", "assetpriorityemail",params);
service.log (’$$SAM$ - entering ASSETPRIORITYVAL’)
# Declare the user input choices and the corresponding functions implemented in this script
cases = {service.YNC_NULL:dflt, service.YNC_YES:yes, service.YNC_NO:no}
# Make sure the choice message is presented only
#if the field validation was triggered from user interface
if interactive:
if priority < 2:
service.log ("About to do something")
# Use the service utility's yncuserinput() method to trigger the entire interaction
# User's response is stored in a local variable x
x = service.yncuserinput()
service.log("User input: "+str(x))
# Process the user input using Jython's case statement
cases[x]()
What to do next
To test your script, in the Assets application, select a
record and set the priority to 1. When a choice message appears, select
a choice.