Automatic Status Changes for Service Requests (SR) with Automation Script

This entry is part 7 of 8 in the series Maximo Automation Scripts

Did You Know...

As Maximo Experts, we have developed several add-on products for Maximo that mobilize the work force, simplifies assignments, provides ad-hoc reporting capabilities and facilitates the seamless integration of Service Requests into Maximo.

Check out our products by clicking on the following links: EZMaxMobileEZPLanner and EZInsight.

Find Out More

12 thoughts on “Automatic Status Changes for Service Requests (SR) with Automation Script

  1. Hi Chon,
    Thanks for posting this great script, however I’m having trouble with the COMP / RESOLVED status change where there is only one workorder linked to the SR and the SR status is INPROG. The first part (changing to INPROG) of the script works perfectly, however when we try to complete a single work order linked to a SR, we are getting the following system message:
    BMXAA8229W – Record SR : Class=SR Service Request=1234 has been updated by another user. Your changes have not been saved. Refresh the record and try again.
    Funny thing is the script works perfectly if there are multiple work orders originating from the same SR. i.e. The SR status changes to RESOLVED when the last work order is completed, or if there is a single work order attached, the script will work so long as the SR status is not in INPROG when trying to complete the linked work order??
    I’m not familiar at all with javascript, and have just followed the steps outlined in your post, so any help you can provide to get this (very useful) script working for us would be greatly appreciated!
    Regards Caleb

      1. Yes we did. One of our javascript guys had to modify the script because maximo natively changes the SR status if a single work order has been generated from a SR (copy and paste has removed all formatting / indentation):

        importClass(Packages.psdi.server.MXServer);
        importClass(Packages.psdi.util.MXException);

        //Check if this workorder is INPRG status
        if (mbo.getString(“STATUS”) == ‘INPRG’)
        {
        //Find the related SR if any
        var sr = mbo.getMboSet(“ORIGTICKET”).getMbo(0);
        //If SR is in QUEUED or NEW status
        if (sr != null && (sr.getString(“STATUS”) == “QUEUED” || sr.getString(“STATUS”) == “NEW”))
        {
        //Change SR status to INPROG
        sr.changeStatus(“INPROG”, MXServer.getMXServer().getDate(), null);
        }
        }
        //Check if this workorder is COMP status
        if (mbo.getString(“STATUS”) == ‘COMP’)
        {
        //Find the related SR if any
        var sr = mbo.getMboSet(“ORIGTICKET”).getMbo(0);
        //If SR is in INPROG status
        if (sr != null && sr.getString(“STATUS”) == “INPROG”)
        {
        //Get all workorders
        var woSet = sr.getMboSet(“WORKORDER”);
        //If more more than one WO exists for an sr
        if (woSet.count() != 1)
        {
        //Get a list of records not in CAN, COMP, CLOSE
        woSet.setQbe(“STATUS”, “DRAFT,WAPPR,APPR,WPCOND,INPRG,WMATL,WSCH”);
        woSet.setQbe(“WORKORDERID”, “!=” + mbo.getUniqueIDValue());
        woSet.reset();
        //If list is empty, it means all the workorders are ‘completed’, then set SR to RESOLVED
        if (woSet.isEmpty())
        {
        sr.changeStatus(“RESOLVED”, MXServer.getMXServer().getDate(), null);
        }
        }
        }
        }
        //Check if this workorder is CLOSE status
        if (mbo.getString(“STATUS”) == ‘CLOSE’)
        {
        //Find the related SR if any
        var sr = mbo.getMboSet(“ORIGTICKET”).getMbo(0);
        //If SR is in RESOLVED status
        if (sr != null && sr.getString(“STATUS”) == “RESOLVED”)
        {
        //Get all workorders
        var woSet = sr.getMboSet(“WORKORDER”);
        //If more more than one WO exists for an sr
        if (woSet.count() != 1)
        {
        //Get all workorders
        var woSet = sr.getMboSet(“WORKORDER”);
        //Get a list of records not in CAN, CLOSE
        woSet.setQbe(“STATUS”, “DRAFT,WAPPR,APPR,WPCOND,INPRG,WMATL,WSCH,COMP”);
        woSet.setQbe(“WORKORDERID”, “!=” + mbo.getUniqueIDValue());
        woSet.reset();
        //If list is empty, it means all the workorders are ‘completed’, then set SR to CLOSED
        if (woSet.isEmpty())
        {
        sr.changeStatus(“CLOSED”, MXServer.getMXServer().getDate(), null);
        }
        }
        }
        }

        1. Hi,

          can we change the status through automation script using maxadmin user. In this way we dont have to give extra rights to usres for change the status in application. everytime when the user will run that script it will change the status using maxadmin. Is it possible?

  2. Howdy,
    This script looks to be very useful. I have tried to implement this on 7.6.0.6. The create wizard is a bit different. There is a choice to select one of five different ways to use the Attribute launch point. Also there is a new variables section. This script does not appear to use those. I have tried implementing this script and have had no success so far. Any insight would be appreciated.

      1. Nothing happens. When I change status form APPR to INPRG the WO changes but the SR does not. So far nothing in logs either. Set debug level to DEBUG and I see the SQL values for the WO but nothing for the SQL call to the SR. I played with this for about two hours before I put in forum comment. Any suggestions for the set up?

          1. This forum. I stole the code and used verbatim. I have turned logging on for AUTOSCRIPT, SQL, APPLICATION for both WOTRACK and SR, and I just do not see it anything firing.

  3. When changing a WO status, this looks at the originating record SR value (on the WO) and then gets all the (potential) other WOs for that same SR to check their statuses. Another scenario is that someone associates multiple SRs to the same WO (think of 5 people reporting the same leak, each call gets an SR, but then only 1 WO is created from the first SR that was called in; all the subsequent SRs can link to the same WO under the Related Records tab > Related Work Orders list). So ideally, you’d want to find ANY SR that it is linked to (using the RELATEDRECORD mbo) and THEN check all the WOs for each SR. Thoughts?

Leave a Reply