Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  Add EMAILADDRESS to EMAIL table using automation script

    Posted 10/08/20 12:37 PM
    Hi,
    I have a custom table (CXPERSON) which has fields EMAIL, OTHEREMAIL1 and OTHEREMAIL2. The custom table will hold email address only any one of the fields ( not necessarily all the 3). For example 

    Scenario 1 - CXPERSON.EMAIL is not null then this value should be copied over to EMAIL.EMAILADDREESS ,
    Scenario 2 - CXPERSON.EMAIL is NULL and CXPERSON.OTHERMAIL1 is not null then this value should be copied over to EMAIL.EMAILADDRESS. 
    Scenario 1 works without any issue however Scenario 2 gives the following error . I'm unable to figure out what could be the problem

    The script is invoked on action launch point in the custom table CXPERSON and moved to the PERSON table.
    personMboSet = mbo.getMboSet("CXPERSON")
    if personMboSet.count()>0:
          personMbo = personMboSet.getMbo(0)
         emailMboSet = personMbo.getMboSet("EMAIL")
         if emailMboSet.isEmpty():
              emailMbo = emailMboSet.add()
               emailMbo.setValue("PERSONID", mbo.getString("PERSONID"))
              if mbo.getString("EMAIL") is not None:
                   emailMbo.setValue("EMAILADDRESS", mbo.getString("EMAIL"))
              elif mbo.getString("OTHERMAIL1") is not None:
                   emailMbo.setValue("EMAILADDRESS", mbo.getString("OTHERMAIL1"))          
              emailMboSet.save()
    personMboSet.save()

    BMXAA6696E - The required field validation in the MBO failed for object EMAIL and attribute EMAILADDRESS. MXAA4195E - A value is required for the E-mail field on the EMAIL object.
    psdi.util.MXRequiredFieldException: BMXAA4195E - A value is required for the E-mail field on the EMAIL object.
    at psdi.mbo.Mbo.throwRequiredException(Mbo.java:4938)
    at psdi.mbo.Mbo.validate(Mbo.java:4742)
    at psdi.mbo.MboSet.validate(MboSet.java:5400)
    at psdi.mbo.MboSet.validateTransaction(MboSet.java:7879)
    at psdi.txn.MXTransactionImpl.validateTransaction(MXTransactionImpl.java:375)
    at psdi.txn.MXTransactionImpl.saveTransaction(MXTransactionImpl.java:207)
    at psdi.txn.MXTransactionImpl.save(MXTransactionImpl.java:156)

    ------------------------------
    MAX092012
    ------------------------------

    #AssetandFacilitiesManagement
    #Maximo


  • 2.  RE: Add EMAILADDRESS to EMAIL table using automation script

    Posted 10/09/20 08:05 AM
    The reason Scenario 1 works and Scenario 2 doesn't is that the statement if mbo.getString("EMAIL") is not None: will always return true, whether there's a value in the EMAIL field or not. If there's no value an empty string will be returned. However, I prefer this syntax: if not mbo.isNull("EMAIL"):

    Give that a try with your IF and ELIF statements. Hopefully that works.

    ------------------------------
    Alex Walter
    ------------------------------



  • 3.  RE: Add EMAILADDRESS to EMAIL table using automation script

    Posted 10/09/20 10:20 AM
    Alex's option is a good one to try. Another option is python can use if statements to handle None or empty string pretty well. We hit some cases where IBM would have a string with a single space so there was no real value in the field. You can use something like:

    if mbo.getString("EMAIL"):

    That will tell you if an actual value (not null, not empty string, etc.) is provided. And you can add the not before in your use case to handle that no real value has been provided. 


    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 4.  RE: Add EMAILADDRESS to EMAIL table using automation script

    Posted 10/09/20 10:56 AM
    Edited by System Admin 03/22/23 11:44 AM
    A few of my rules for automation scripting are broken by your script.
    1. Avoid calling MboSet.count() and MboSet.isEmpty(). It is usually better for performance and code simplicity to test whether you got something back from MboSet.getMbo() or MboSet.moveXxxx().
    2. Python allows you to test for both the pointer not being null and the string not being empty with if myString: or if stringReturningFunction():. Use this feature to simplify your code. Like @Alex Walter, I would prefer not mbo.isNull() in this scenario, but for your learning I'll not use it.
    3. Do not call save() on MboSets that you did not get from MXServer for yourself.
    Also, if your launch point is on CXPERSON, then mbo will be pointing at a CXPERSON. And if that's the case, then shouldn't the relationship you use from mbo be PERSON, making your first line be personMboSet = mbo.getMboSet("PERSON") without the CX prefix on PERSON?

    Applying these rules and thoughts to your script, we get the following.

    personMboSet = mbo.getMboSet("PERSON")
    personMbo = personMboSet.getMbo(0)
    if personMbo:
        emailMboSet = personMbo.getMboSet("EMAIL")
        emailMbo = emailMboSet.getMbo(0)
        if not emailMbo:
            emailMbo = emailMboSet.add()
            emailMbo.setValue("PERSONID", mbo.getString("PERSONID"))
            if mbo.getString("EMAIL"):
                emailMbo.setValue("EMAILADDRESS", mbo.getString("EMAIL"))
            elif mbo.getString("OTHERMAIL1"):
                emailMbo.setValue("EMAILADDRESS", mbo.getString("OTHERMAIL1"))​


    If your business case allows it, maybe you can use different rows in EMAIL with different TYPEs instead of keeping CXPERSON sync'd with EMAIL.

    ------------------------------
    Blessings,
    Jason Uppenborn
    Sr. Technical Maximo Consultant
    Ontracks Consulting
    ------------------------------



  • 5.  RE: Add EMAILADDRESS to EMAIL table using automation script

    Posted 10/16/20 01:17 PM
    Hi All,
    Thank you very much for your guidance I was able to resolve the issue based on the comment from Jason & Alex. Thanks once again!!

    ------------------------------
    MAX092012
    ------------------------------