Maximo Open Forum

 View Only
  • 1.  Automatically generate workorder 6 months before a warranty contract expires

    Posted 03-22-2024 09:03

    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
    ------------------------------


  • 2.  RE: Automatically generate workorder 6 months before a warranty contract expires

    Posted 03-26-2024 09:34

    Hi @Danny Cordeau! I was thinking. It's complex.

    Some ideas I can give you:
    - Create an escalation on CONTRACT for contracttype = 'WARRANTY' where sysdate - 180 <= CONTRACT.ENDATE.
    The first and simplest thing is to notify you and you can at least know that that time period has been reached.

    Now, create a work order. You could try to execute an action associated with the escalation of type "Application Action" with the value "CREATEWO".

    Another possible idea would be to create a work order from a PM. It remains to resolve how to update the generation date (PM.NEXTDATE)... perhaps an escalation or also the possibility of doing an update type import.

    I'll try to see if I can replicate it exactly as you need it and I'll let you know.

    Regards!



    ------------------------------
    Martin Fabra
    ARSAT S.A. - Actively seeking employment
    ------------------------------



  • 3.  RE: Automatically generate workorder 6 months before a warranty contract expires

    Posted 30 days ago

    Hi Martin!

    Thanks for your input! I will look onto you tips and try to figure the best way to achieve my goal. In the meantime, don't hesitate to share me the results of your research.

    Have a nice day!

    Danny



    ------------------------------
    Danny Cordeau
    Universite de Sherbrooke
    ------------------------------



  • 4.  RE: Automatically generate workorder 6 months before a warranty contract expires

    Posted 29 days ago

    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
    ------------------------------



  • 5.  RE: Automatically generate workorder 6 months before a warranty contract expires

    Posted 29 days ago

    Thanks Jason for your post!

    As I said in my original message, I am new to Automation Script but be sure that I will look closely to the script you posted.

    Have a nice day!

    Danny



    ------------------------------
    Danny Cordeau
    Universite de Sherbrooke
    ------------------------------