How to Rollup Cost with the Automation Script

This tutorial will show you how to rollup the cost of labor and materials into a new field on a work order using the Automation Script.

Step 1:

In the Database Configuration, create a new field on the WORKORDER object called “TOTALCOST” with TYPE = ‘AMOUNT’ as in this screenshot:

RollupCost_1

Be sure to Select Action -> Apply Configuration Changes when done.

Step 2:

In the Application Designer, open the WOTRACK app and add the new ‘textbox’ any where on the details screen.  Set the attribute to “TOTALCOST”

Step 3:

Go to System Configuration -> Platform Configuration -> Automation Scripts and click Select Action -> Create -> Script with Object Launch Point.  A dialog will pop up and enter the following and click ‘Next’:

RollupCost_2

Enter the Launch Point Name = “ROLLUPCOST” and the Object = “WORKORDER”.  Also check the “Update?” checkbox.   This will create a new script that will launch anytime a WORKORDER object is updated.

Next, in the following screen, enter the following:

RollupCost_3

Enter the Script name = “ROLLUPCOST_SCRIPT” and description and the Language = “javascript”.  For the language, you can choose anyone you are comfortable with and click ‘Next’.

Step 4:

Now we can write some code!  The idea is to retrieve all the records from the LABTRANS and MATUSETRANS associated with the current workorder record and sum the values and save it into the new TOTALCOST field we created.  Here is the code to do just that:

var lt_linecost = mbo.getMboSet("LABTRANS").sum("LINECOST");
var mut_linecost = mbo.getMboSet("MATUSETRANS").sum("LINECOST");
var totalcost = 0;

if (lt_linecost) totalcost += lt_linecost;
if (mut_linecost) totalcost += mut_linecost;

mbo.setValue("TOTALCOST", totalcost.toString());

Let’s see what we did here.  First, the ‘mbo’ variable is the current WORKORDER object we are working with.  From there, we get all the records associated with that workorder from the LABTRANS and MATUSETRANS relationships.  Then we sum the cost from the LINECOST field.  Once we have the totals, we can then set the value of the TOTALCOST field we added in Step 1.

Step 5:

Next click ‘Create’ and be sure to change the status to ‘ACTIVE’ on the ROLLUPCOST_SCRIPT object we just created.  To test this new script, open any work order and add some actual labor and material costs and click ‘Save’.  Once the record is updated, the new field will now be populated with the correct totals.

Note: 

If the field doesn’t update, try modifying any field on the WORKORDER record itself, like the DESCRIPTION and then hitting save.  Doing this will trigger the update on the record and run this script.  This may be a bug in early versions of Maximo 7.5.

Series Navigation< Disable Maximo business rule with an Automation ScriptAutomation Script: params variable not working with JavaScript language >

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

One thought on “How to Rollup Cost with the Automation Script

  1. Wouldn’t it be best to trigger this autoscript with a escalation so that Work Orders are updated without having to edit or save them? You can add labor or material to a Work Order via other applications, by doing that would that update the totalcost field?

Leave a Reply

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