Pages

Tuesday, February 28, 2017

Yes No Exception Handling in Maximo 7.6 Automation Script (Gathering User Input)

A company requires to send email to the owner of work order when the highest priority is set in the work order priority. An automation script is used to send this email. The automation script uses a choice that confirms to email should be sent.


Steps:


  1. In the database configuration application, from the select action Messages create a new message with following values:

    Message Group: workorder
    Message Key: wopriorityemail
    Display Method: MSGBOX
    Message ID Prefix: BMXZZ
    Message ID Suffix: W
    Display ID: 1
    Value: Work Order owner can be notified through email when priority {0} is set. Send email?
    Buttons: Yes, No
  2. In the Automation Scripts application, create an attribute launch point with the following options:

    Object: WORKORDER
    Attribute: WOPRIORITY
    Event: Run Action
    Log Level: Debug
  3. Enter the following code and create the automation script:
from psdi.server import MXServer

# Logic to implement when user clicks YES
def yesAction ():
    service.log("Sending Email")
    MXServer.sendEMail(<To Email>,<From Email>,<Subject> ,<Body>)

# Logic to implement when user clicks NO
def noAction ():
    service.log("Not Sending Email")

# Logic to present the choice message initially
def defaultMsg ():
    params=[str(priority)]
    # Use the service utility's yncerror() method to push the choice message
    service.yncerror("workorder", "wopriorityemail",params);

# Declaring the user input choices and the corresponding functions
cases = {service.YNC_NULL:defaultMsg,service.YNC_YES:yesAction,service.YNC_NO:noAction}

# Make sure the choice message is presented only 
#if the field validation was triggered from user interface
if interactive:
    if priority < 2:
        # Use the service utility's yncuserinput() method to trigger the interaction
        # User's response is stored in a local variable userChoice
        userChoice = service.yncuserinput()
        # Process the user input using Python's case statement
        cases[userChoice]()

No comments:

Post a Comment