- Prevent completion / closure of work orders with open labor transactions
- Your first Automation Script in Maximo 7.5
- Disable Maximo business rule with an Automation Script
- How to Rollup Cost with the Automation Script
- Automatic Status Changes for Service Requests (SR) with Automation Script
- A Collection of Maximo Automation Script Examples
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.
In the Database Configuration, create a new field on the WORKORDER object called “TOTALCOST” with TYPE = ‘AMOUNT’ as in this screenshot:
Be sure to Select Action -> Apply Configuration Changes when done.
In the Application Designer, open the WOTRACK app and add the new ‘textbox’ any where on the details screen. Set the attribute to “TOTALCOST”
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’:
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:
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.
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.
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.