Here is a script that does what you are looking for, just set it up to run as a CronTask. Documentation can be found here: https://www.ibm.com/docs/en/mfci/7.6.2?topic=tasks-creating-cron-that-run-automation-scripts
Note that I am using the work order description to identify previously created work orders, which isn't great. You should set up an attribute to track this and check that instead, but as an example of how to approach this it is hopefully helpful.
I have included a scriptConfig variable as well so if you are using the VS Code Developer tools you can just deploy it directly.
https://marketplace.visualstudio.com/items?itemName=sharptree.maximo-script-deploy
Regards,
Jason
Calendar = Java.type("java.util.Calendar");
MboConstants = Java.type("psdi.mbo.MboConstants");
SqlFormat = Java.type("psdi.mbo.SqlFormat");
MXServer = Java.type("psdi.server.MXServer");
MXFormat = Java.type("psdi.util.MXFormat");
var MONTHS = 6;
main();
function main(){
// check if the implicit runAsUserInfo variable is available so we know we are running in a cron task.
if(typeof runAsUserInfo !== 'undefined'){
var warrantySet;
try{
warrantySet = MXServer.getMXServer().getMboSet("WARRANTYVIEW",runAsUserInfo);
var calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, MONTHS);
// use a SqlFormat to construct a where clause
// https://www.sharptree.io/blog/2022/2022-01-31-sql-format/
var sqlf = new SqlFormat("enddate < :1 and status in (select value from synonymdomain where maxvalue = 'APPR')");
sqlf.setObject(1, "WARRANTYVIEW", "ENDDATE", MXFormat.dateToString(calendar.getTime()));
warrantySet.setWhere(sqlf.format());
// get the first expiring warranty or null
var warranty = warrantySet.moveFirst();
// for the first loop, if there was warranty expiring then we have it, otherwise this evaluates null and nothing happens
// this will then loop over any other records in the set until all the warranties have been processed
while(warranty){
createWorkOrderForWarranty(warranty);
warranty = warrantySet.moveNext();
}
}finally{
try{
// https://www.sharptree.io/blog/2021/2021-11-22-close-things/
if(warrantySet){
warrantySet.close();
warrantySet.cleanup();
}
}catch(ignored){} // ignore errors closing MboSets because there is nothing we can do about it.
}
}
}
function createWorkOrderForWarranty(warranty){
var workOrderSet;
try{
workOrderSet = MXServer.getMXServer().getMboSet("WORKORDER",runAsUserInfo);
var contractAuthSet = warranty.getMboSet("CONTRACTAUTH");
var contractAuth = contractAuthSet.moveFirst();
while(contractAuth){
var sqlf = new SqlFormat("description = :1 and siteid = :2");
// This isn't ideal and a real solution should use a more explicit way of identifying that a work order was created for the warranty expiration.
sqlf.setObject(1, "WORKORDER","DESCRIPTION", "Notice for warranty: " + warranty.getString("CONTRACTNUM"));
sqlf.setObject(2, "WORKORDER", "SITEID", contractAuth.getString("AUTHSITEID"));
workOrderSet.setWhere(sqlf.format());
workOrderSet.reset();
// if a work order has not been created yet
if(workOrderSet.isEmpty()){
var workOrder = workOrderSet.add();
workOrder.setValue("DESCRIPTION", "Notice for warranty: " + warranty.getString("CONTRACTNUM"));
// force the Site Id to match the contract authorization site
workOrder.setValue("SITEID", contractAuth.getString("AUTHSITEID"), MboConstants.NOACCESSCHECK);
// In case you want to put the work order into workflow here is how you do it.
// MXServer.getMXServer.lookup("WORKFLOW").initiateWorkflow("YOUR_PROCESS_NAME_HERE", workOrder);
workOrderSet.save();
}
contractAuth = contractAuthSet.moveNext();
}
}finally{
try{
if(workOrderSet){
workOrderSet.close();
workOrderSet.cleanup();
}
}catch(ignored){} // ignore errors closing MboSets because there is nothing we can do about it.
}
}
var scriptConfig={
"autoscript": "WARRANTY.EXPIRATION",
"description": "Watch for warranties that are 6 months from ending.",
"version": "",
"active": true,
"logLevel": "ERROR"
};
------------------------------
Jason VenHuizen
Sharptree
------------------------------
Original Message:
Sent: 03-22-2024 09:02
From: Danny Cordeau
Subject: Automatically generate workorder 6 months before a warranty contract expires
Hi,
Maximo 7.6.1.3 here.
Is there a way to automatically generate a workorder 6 months prior to the end of a warranty contract?
Right now, my options are an escalation that check the ENDDATE=-180 of the contract, an automation script in which I am a newbie and lastly, a preventive maintenance created at the same time as the warranty contract.
All suggestions are welcome.
Thanks!
Danny
#Administration
#EverythingMaximo
------------------------------
Danny Cordeau
Universite de Sherbrooke
------------------------------