Maximo Open Forum

 View Only
  • 1.  Communication template adding all worklogs

    Posted 10-23-2023 23:13

    7.6.1.3

    I am a little newbie to communication template:  Looking for a way to includes all worklogs with "viewable checked" to a communication template. 

    My unsuccessful attempts was able to only add the latest worklog entry.


    #EndUser

    ------------------------------
    Loc Chu
    Peacehealth
    ------------------------------



  • 2.  RE: Communication template adding all worklogs

    Posted 10-24-2023 08:46
      |   view attached

    As far as I am aware, out-of-the-box Maximo doesn't allow for enumeration of child records w/in communication templates (i.e. there's not a way provided to list all work log entries, for example).

    We have worked around this using the following approach:

    1) make up some short of placeholder like #WORKLOG# and add that to the message of your communication template.

    2) add an automation script that runs whenever the message body is updated--this script should look for #WORKLOG#.

    3) if that placeholder is found, the script opens the appropriate MBO set and either builds a list or a table of work log entries and then replaces the placeholder #WORKLOG# with the HTML (list, table, etc).

    I've attached our script--I am definitely on the amateur side of scripting, and so I'm sure others could provide insights about how to do this better...but this approach has worked for us!



    ------------------------------
    Jade Warren
    Great River Energy
    ------------------------------

    Attachment(s)

    txt
    commlog_msg.txt   47 KB 1 version


  • 3.  RE: Communication template adding all worklogs

    Posted 10-24-2023 11:51

    Thank you Jade.  This explains why I'm unable to find a simple solution.  With MAS approaching, there is no need to request IBM to add a simple solution to future updates. 

    Thank you very much for the attachment.  You went be on just answering a question, but also found and provided a solution. 



    ------------------------------
    Loc Chu
    Peacehealth
    ------------------------------



  • 4.  RE: Communication template adding all worklogs

    Posted 08-13-2024 12:08
    Edited by Matt F 08-13-2024 12:10

    Hi Jade,

    I just wanted to publicly thank you for sharing your efforts on the scenario you were able to meet with the provided automation script. This allowed me to easily fulfill a similar use case in the SR app. Cheers!



    ------------------------------
    Matt F
    ------------------------------



  • 5.  RE: Communication template adding all worklogs

    Posted 12-10-2024 02:53

    Hello Jade,

    I'm having the same problem as the original poster and I'm eager to try out your method. I just have a few extra questions.

    In what script language is your script written? Python?

    And if I wanted to create the same effect for let's say all the materials that were used, could I simply make a new placeholder (#MATUSE#) and then update all relevant lines in your script?

    Thank you for you time,

    Sammy-Joe



    ------------------------------
    Sammy-Joe Goossens
    DHL Aviation
    ------------------------------



  • 6.  RE: Communication template adding all worklogs

    Posted 12-10-2024 18:32
    Edited by Matt F 12-10-2024 18:34

    Hi Sammy-Joe,

    I did a quick test with a Python script to build out a table of Actual Materials (you'll need to add more if you wanted to include Planned as well). Aside from the script, I created a Relationship on the COMMLOG object to WORKORDER and leveraging the existing Relationship to MATUSETRANS on the WORKORDER object. The read-only conditions may not be required in your case, if so, you can strip it out.

    See below:

    from psdi.mbo import MboConstants
    
    # Specify the TEMPLATEIDs for which this script should run
    target_template_ids = ["ACT_MATERIAL"]  # Replace with the specific TEMPLATEIDs you want
    
    # Ensure mbo is not None and based on COMMLOG
    if mbo is not None and mbo.isBasedOn("COMMLOG"):
        commlog = mbo 
    
        # Always reset read-only status for MESSAGE and SUBJECT fields
        commlog.setFieldFlag("MESSAGE", MboConstants.READONLY, False)
        commlog.setFieldFlag("SUBJECT", MboConstants.READONLY, False)
    
        # Check if the TEMPLATEID matches the specific ones we want to handle
        if mbo.getString("TEMPLATEID") in target_template_ids:
            # Get the related WORKORDER MboSet and move to the first record
            workorder_set = commlog.getMboSet("WORKORDER")
            workorder = workorder_set.moveFirst()
    
            # Check if the workorder is not None before processing
            if workorder is not None:
                relationship_name = "SHOWACTUALMATERIAL"  # Relationship name to the Materials from WORKORDER
    
                # Fetch the related MBO set of Materials with ORDERBY clause if preferred
                materials = workorder.getMboSet(relationship_name)
                materials.setOrderBy("LINETYPE ASC")  
    
                # Initialize the table structure with headers
                materials_table = (
                    '<table border="1" style="width:600px; table-layout:auto; border-collapse:collapse; margin:0;">'
                    '<tbody>'
                    '<tr>'
                    '<td style="white-space:nowrap; padding: 5px; border: 1px solid #ccc;"><strong>Line Type</strong></td>'
                    '<td style="white-space:nowrap; padding: 5px; border: 1px solid #ccc;"><strong>Description</strong></td>'
                    '<td style="white-space:nowrap; padding: 5px; border: 1px solid #ccc;"><strong>Quantity</strong></td>'
                    '<td style="white-space:nowrap; padding: 5px; border: 1px solid #ccc;"><strong>Line Cost</strong></td>'
                    '<td style="white-space:nowrap; padding: 5px; border: 1px solid #ccc;"><strong>Unit Cost</strong></td>'
                    '<td style="white-space:nowrap; padding: 5px; border: 1px solid #ccc;"><strong>Issue Type</strong></td>'
                    '</tr>'
                )
    
                # Loop through each Material and add rows to the table
                if not materials.isEmpty():
                    for i in range(materials.count()):
                        material = materials.getMbo(i)
                        # Extract necessary fields from the Material Mbo
                        line_type = material.getString("LINETYPE")
                        description = material.getString("DESCRIPTION")
                        positive_quantity = material.getString("POSITIVEQUANTITY")
                        line_cost = material.getString("LINECOST")
                        unit_cost = material.getString("UNITCOST")
                        issue_type = material.getString("ISSUETYPE")
                        
                        # Add a row to the table with the material details
                        materials_table += (
                            '<tr>'
                            '<td style="white-space:nowrap; border: 1px solid #ccc;">' + line_type + '</td>'
                            '<td style="white-space:nowrap; border: 1px solid #ccc;">' + description + '</td>'
                            '<td style="white-space:nowrap; border: 1px solid #ccc;">' + positive_quantity + '</td>'
                            '<td style="white-space:nowrap; border: 1px solid #ccc;">' + line_cost + '</td>'
                            '<td style="white-space:nowrap; border: 1px solid #ccc;">' + unit_cost + '</td>'
                            '<td style="white-space:nowrap; border: 1px solid #ccc;">' + issue_type + '</td>'
                            '</tr>'
                        )
    
                # Close the table
                materials_table += (
                    '</tbody>'
                    '</table>'
                )
    
                # Cleanup and close the MboSet
                materials.close()
    
                # Inject the generated table into the MESSAGE field of the Communication Template
                if materials_table:
                    # Replace the placeholder in the communication template, e.g., `#MATUSETRANS#`
                    message = commlog.getString("MESSAGE")
                    updated_message = message.replace("#MATUSETRANS#", materials_table)
                    commlog.setValue("MESSAGE", updated_message, MboConstants.NOACCESSCHECK)
    
            # Set the MESSAGE/SUBJECT field to read-only for the specific templates
            commlog.setFieldFlag("MESSAGE", MboConstants.READONLY, True)
            commlog.setFieldFlag("SUBJECT", MboConstants.READONLY, True)

    Hope this helps. Let us know how you make out. 

    Cheers,



    ------------------------------
    Matt F
    ------------------------------



Newest Episode
Ep. 5 | Make Manage Feel Like Home with Configuration, Not Customization

Watch Steven Shull and Phil Runion discuss how IBM Maximo Manage teams can make the system feel more familiar, useful, and aligned to their business through configuration instead of customization.

MORE by Naviam Episode 5 cover
Watch Episode 5
Also available: Ep. 4 | System Properties in IBM Maximo