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

There are many organizations that want to automatically change the status of an SR to in progress or resolved whenever one or more workorders have been started or completed.  In this tutorial, we will create an automation script that will automatically change the status of the SR when a related work order is changed to in progress.  Also, if an SR has multiple workorders, change the status of the SR to RESOLVED when all related workorders are completed.

In this first half of this tutorial, we will setup a script that will change the status of the SR from QUEUED or NEW to INPROG whenever a workorder status is changed to INPRG.

Step 1:

Create a new automation script with an attribute launch point on the STATUS field on the WORKORDER object.  First Go To -> System Configuration -> Platform Configuration -> Automation Scripts.  Click Select Action -> Create -> Script with Attribute Launch Point.  In this step, set the name of the launch point to SRSTATUS with a description of ‘SR Status Change’.  Then set the object to WORKORDER and attribute equal to STATUS.  Then click Next.

SRStatus_Script

Step 2:

Set the script name to ‘SRSTATUS’ and the description of ‘SR Status Change’ (You can change these to whatever you want, but for simplicity sake, we just name it the same as the launch point).  Then set the language to ‘javascript’.  This is my preferred language and you can use any one you want, but the code below is for javascript.  Then click Next.

Step 3:

Copy and paste this code:

importClass(Packages.psdi.server.MXServer);

// 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);
	}
}

And click Create.

Let’s analyse this code.  First we check if the current MBO (in this case, it’s the work order MBO) status is equal t0 INPRG.  If so, find the related SR if any and if the SR status is equal to QUEUED or NEW, then change the status to INPROG.  Simple enough, how let’s test it.

Step 4:

Now the script is created, we can test it out.  Find a work order in APPR status that also has an SR related to it and change the work order status to INPRG.  You should get a dialog like so:

SRStatus_Dialog

So now, when any workorder status is changed to INPRG, the related SR will also be changed.  But what about when an SR has multiple work orders and when all the work orders are completed, can we change the SR to RESOLVED?  Yes we can.

Step 5:

First we have to edit the existing script we just created.  Find the SRSTATUS script and edit the code.  The complete code should look like this:

importClass(Packages.psdi.server.MXServer);

// 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");
		// Get a list of records not in CAN, COMP, CLOSE
		woSet.setQbe("STATUS", "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);			
	}
}

Let’s analyse this code.  You can see we added another section to check when the work order status is COMP, then find the related SR.  If the SR is currently INPROG, then check to see if there is a list of workorders associated with it.  Then check if all the work orders are completed and if so, set the SR to RESOLVED.

Step 6:

Now you can test this and now the status should be changed to RESOLVED when all work orders are completed.

There are somethings to consider with this.  In this script, we are checking if the status is COMP so when the last work order to be completed is changed, it will change the status of the SR.  But if the last work order status is changed to CAN or CLOSE, then the last section of the script won’t execute.  This is something to consider and you can simply resolve that by added another condition to the last “if” statement.

UPDATE:

Here is an updated code based on the comments below… Thanks guys!

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);
            }
        }
    }
}

Series Navigation< Import Classes and Packages using Javascript Language and Automation ScriptsA Collection of Maximo Automation Script Examples >

Did You Know...

As Maximo Experts, we have developed Maximo adds on products to make Maximo work assignment simple, reporting easy, and facilitating service requests seamless. Check out our additional products EZPlanner, EZInsight, and EZRequest.

Find Out More

10 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. Awesome! Thanks! I appreciate the reply and Chon can probably update the post to reflect your modified script.

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

Leave a Reply

Your email address will not be published. Required fields are marked *