Hi!
I've created an automation script for running and saving a report in a communication template when a new workorder is saved.
Every thing works as expected except the fact that it's ran twice, which could cause performance issues.
I'm thinking that my launch point could be the reason for this:
I've tried After Commit and I've also tried unchecking Update but the script still runs twice. I want this script to run every time a new workorder record is created, and everytime it's updated after that so that a new report is saved if data is updated in the workorder. Is there anyone that can see what I'm doing wrong? :)
Script:
from psdi.mbo import Mbo, MboConstants from psdi.util.logging import MXLoggerFactory from psdi.server import MXServer import time from com.ibm.tivoli.maximo.report.birt.admin import ReportAdminServiceRemote from com.ibm.tivoli.maximo.report.birt.runtime import ReportParameterData from java.io import FileOutputStream # Logg logger = MXLoggerFactory.getLogger("maximo.custom.warrantyreport") logger.debug("Entering WORKORDER.WARRANTYREPORT") # Rapportnamn & rapportmapp reportName = "plustwoprint2.rptdesign" appName = "PLUSTWO" reportFolder = "AO-detaljer" # Mapp för att spara rapport som bilaga # Kontrollera att det inte finns någon tidigare statushistorik och att det är en reklamasjonsarbetsorder (WORKTYPE = 'REKLM')) worktype = mbo.getString("WORKTYPE") logger.debug("Worktype: " + str(worktype)) if worktype == "REKLM": logger.debug("Condition met: PreviousValue is None and Worktype is REKLM. Proceeding...") wonum = mbo.getString("WONUM") # Hämta rapportmappens path logger.debug("Retrieving folder for file") userinfo = MXServer.getMXServer().getSystemUserInfo() doctypesMboSet = MXServer.getMXServer().getMboSet('DOCTYPES', userinfo) doctypesMboSet.setWhere("DOCTYPE='" + reportFolder + "'") outputFilePath = doctypesMboSet.getMbo(0).getString('DEFAULTFILEPATH') doctypesMboSet.cleanup() doctypesMboSet.close() # Sätter output-information logger.debug("Output folder: " + outputFilePath) fileName = "WarrantyWorkorder-" + wonum +"-Report-" timestr = time.strftime("%d%m%Y-%H%M") outputFileName = fileName + timestr + ".pdf" outputFile = outputFilePath + "\\" + outputFileName logger.debug("Output file: " + outputFile) logger.debug("Generating report " + reportName) # Genererar rapport reportAdminService = MXServer.getMXServer().lookup("BIRTREPORT") parameterData = ReportParameterData() parameterData.addParameter("where", "(workorder.wonum='"+wonum+"' and workorder.siteid='MS')") reportBytes = reportAdminService.runReport(userinfo, reportName, appName, parameterData, outputFileName, ReportAdminServiceRemote.OUTPUT_FORMAT_PDF) # Skriver den binära datan till outputfilen fos = FileOutputStream(outputFile) fos.write(reportBytes) fos.close() #Sletter doclinker til tidligere versjoner av denne rapporten #Commlog-vedleggene på posten vil fortsatt ligge som linker til tidligere versjoner, men vil ikke komme med på mailen. doclinksMboSetDelete = mbo.getMboSet("DOCLINKS") doclinks=doclinksMboSetDelete.moveFirst() while doclinks is not None: if doclinks.getString("OWNERTABLE")=="WORKORDER" and doclinks.getString("DOCTYPE")=="AO-Detaljer": logger.debug("Deleting old doclinks post, DESCRIPTION: " +doclinks.getString("DESCRIPTION")) doclinks.delete() doclinks=doclinksMboSetDelete.moveNext() # Oppretter linker mot doclinks doclinksMboSet = mbo.getMboSet("DOCLINKS") doclinksMbo = doclinksMboSet.add() doclinksMbo.setValue("URLTYPE", "FILE") doclinksMbo.setValue("URLNAME", outputFile) doclinksMbo.setValue("NEWURLNAME", outputFile) doclinksMbo.setValue("DOCTYPE", reportFolder) doclinksMbo.setValue("ADDINFO", True) doclinksMbo.setValue("DESCRIPTION", "Warranty workorder " + wonum + "-" + timestr) doclinksMboSet.save() logger.debug("After added doclinks") logger.debug("Doclinks - URLNAME:" + doclinksMbo.getString("URLNAME")) logger.debug("Doclinks - DOCUMENT: " + doclinksMbo.getString("DOCUMENT")) logger.debug("Exiting WORKORDER.WARRANTYREPORT")
Hi Sally,
I've tried to set up exactly the same configuration for launch point as yours
logPrefix = service.getScriptName() + " -> " service.log(logPrefix + " BEGIN") service.log(logPrefix + " END")
and the result was only single execution of Automation Script. I've also tried with your script and the result was the same - worked properly!
So, I would say it's not the launch point configuration the source of problem.
Something which comes to my mind, as a reason for triggering automation script multiple times (and worth to check in your case) are:
Database Triggers or Integrations - also custom database triggers or integrations outside of Maximo can update the same object, causing a re-save and triggering the script again.
Maybe the good idea will be set SQL logging to INFO and check in logs if for standard save operation on Work Order object there are no two (or more) updates send to database (UPDATE SQLs generated), and - if so - find the reason for this!
RegardsPiotr Ozaist
Thanks for taking your time to even try it in your own envrionment, I really appreciate it. The fact that it worked for you made me look further and troubleshoot with a coworker of mine. The script was never ran twice, the log debuggers were printed twice due to how I set it up in Logging application. If I hadn't touched the log in the logging application I wouldn't have been here. I checked the box below which is what was the reason:
3815 Harrison AvenueCincinnati, OH 45211contact@moremaximo.com
Join CommunityInvite ColleaguesLearn MoreAbout UsTerms of Use