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
------------------------------
Original Message:
Sent: 12-10-2024 02:52
From: Sammy-Joe Goossens
Subject: Communication template adding all worklogs
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
Original Message:
Sent: 10-24-2023 08:46
From: Jade Warren
Subject: Communication template adding all worklogs
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
Original Message:
Sent: 10-23-2023 22:31
From: Loc Chu
Subject: Communication template adding all worklogs
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
------------------------------