Sunday, February 2, 2014

Communication template email via scripting in Maximo

We can trigger email notification with Communication Template with Automation Scripts.
It is needed only if the Application doesn't have the feature.

The Approach is to use Communication Template functionality, and trigger email send through script.
1. Configure Communication Log in the Application, let us say Asset Application







1.1 Add the tab with the below tag in Asset.xml







2. Create Relationship between ASSET and COMMLOG
Condition: ownerid in (select assetuid from asset where assetnum=:assetnum and siteid = :siteid) and ownertable = 'ASSET'



3. Create a Communication template for Asset application with comm. Log entry flag set to 1.

4. Create a Attribute Launch Point Script


When ever there is a change in Asset Status, this script will send an email to User based on the Communication Template.
 


if (STATUS_modified is not None):
      # whereclause is a string with condition to select a comm.template
      whereclause = "TEMPLATEID ='TEST'"

      # Get the Communication template via Asset relationship to send email  
      # mbo is implicit asset object through which we get a template             
      ctMboSet = mbo.getMboSet("$commtemp","COMMTEMPLATE",whereclause);
      ctMboSet.setQbeExactMatch("true")
      ctMboSet.reset()
      ctMbo = ctMboSet.getMbo(0)
      
      if(ctMbo is not None):
          ctMbo.sendMessage(mbo,mbo);



5. Check the change status log in Communication Log tab.



20 comments:

  1. excellent script; have not tested it; but one question have you got this script in javascript version as jython does not work on our version maximo; furthermore i notice the script does not require importing any packages to run this script; am i to assume this code will still work?

    ReplyDelete
    Replies
    1. citizenX :- I dont have the Javascript version with me. By default, all versions of maximo support jython scripting. This code will work without importing any packages, as it uses implicit variable mbo and relationship. you can try it in your maximo.

      Delete
  2. can you explain what the significance of the wherecaluse please as well as the rest of the code

    ReplyDelete
  3. Is there anyway we can have comments on the script, at best code is confusing as there variables that seem to come out of no where, on the print screen there is a variable declared as send mail, what is c-send? As well as templatid=test is that a relation ship name, where did the where clause come from

    ReplyDelete
    Replies
    1. I entered some comments in the code. ctMbo is the object for communication template which send email by sendMessage method. COMMTEMPLATE is the relationship name. TEMPLATEID = 'TEST' is the condition to choose the template from the list of records in the object, similar to selecting a record from a table.

      Delete
  4. I am learning Maximo customization can please suggest me some tutor or pdf ...i searched Google but no use please suggest me some guidelines.

    ReplyDelete
    Replies
    1. Learn Core Java. It will help you to understand the Maximo Java design.

      Delete
  5. Hi Surendar, its really great maximo tips from you.. :)
    I already use it and working verynice.
    But it some case I need to list several value in communication template
    do you know how to make it? for example, I would like to inform someone when there is a PO changes to CLOSE, in email body I need to list all related WO regarding to that PO. I already try to use :poline.refwo but its just show only 1 WO meanwhile on that PO has 2 or more WO reference.

    thanks in advance...

    ReplyDelete
    Replies
    1. MXServer.sendEMail(emailTo, emailFrom, emailSubject, emailBody);

      In your case, you need to use this API to send an email to user from scripting.

      You can refer my post "Automation Script to Run Database scripts as a cron task " .it has a code link to refer.

      Delete
  6. Very informative post! I have a question though, is there a way to pass parameters to the sendMessage() method to add additional recipients to the configuration template? Just as you would do when creating a notification from an mbo on the front end that you get to pick your recipients. (per say, workorder app, select action, create notification, select recipients, send)

    ReplyDelete
    Replies
    1. Forgot to say Thanks in advance and again, great post!

      Delete
    2. To add more recipients, please do use Communication template --> Recipients tab. In this design, the template is fixed, but email receiver can be made dynamic like Asset owner or custodians.

      sendMessage is to mention the Mbo associated with the template.
      sendMessage();
      sendMessage(MboRemote targetMbo);
      sendMessage(MboRemote targetMbo, MboRemote originatingMbo);

      Delete
    3. I see. Is there any other approach I can use to add additional recipients to the email using an autoscript? So far I'm trying to replicate what you would do on the front end from (per say) workorder, where you can send an email using an existing commteplate but you can add recipients to that particular email without permanently changing the communication template. I've been trying to use the following code on a script but have been so far unsuccessful (it does send the email, but doe snot update the send to recipients which is what I'm trying to do):
      ctMbo.setValue("TOLIST",xlist)
      ctMbo.addPersonRecipients(xPersonSet)
      ctMbo.updateRecipientList("SENDTO")
      ctMbo.sendMessage(mbo,mbo)
      listofre=ctMbo.getString("TOLIST")

      Delete
    4. I am also facing the same issue. Did you manage to update SENDTO?

      Delete
  7. Hi, I just want to ask related to this regarding scheduling reports and send email with pdf attachment, it works the sample automation script provided By IBM but, the PDF attached has no data row fetched meaning its empty but the report header is there. thanks if you have some additional information on this.

    ReplyDelete
    Replies
    1. Please check whether 1) You can manually run the report & export as PDF without any issue then 2) Schedule the report from Report Administration application and check your configured email received report in PDF format.

      Delete
    2. Thanks Surendar for your reply. Yes it works manually of having a lot of steps to do course without issue, but the requirements is that without user intervention and to reduce the time to run the report and send email programmatically using Maximo Automation Script. Thanks.

      Delete
    3. I think Surendar, you have to try this as well avoid Manually try Automation Script, there's a lot of things you can achieve in this Script in Maximo fully automated without a need of Java Customization as much as possible.

      Delete
  8. GoodWork Suren. I am going to use this.

    ReplyDelete
  9. Can we use automation script to bring up Communication Template based on the current record? It would be the same screen as Select Action > Create > Communication and a communication template pre-selected. One of our users wants a template, but also wants the ability to edit the e-mail before it goes out.

    ReplyDelete