Maximo Automationscript¶
Example to create and update a workorder:¶
Node configuration¶
"saveAction": {
"url": "insight/eam/rpc/INSIGHT_SAVE_WO"
},
Script¶
- Action: Create -> Script
- Script: INSIGHT_SAVE_WO
- Description: Create or update a workorder from Insight
- Script language: groovy
- Click Next
- Insert script code
- Click Create
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.SqlFormat;
import gis.maximo.insight.rest.rpc.Callback;
MboSetRemote woSet = session.mboSet("WORKORDER");
MboRemote workorder;
if (!binding.hasVariable("WORKORDERID") || WORKORDERID.isEmpty()) { // create
workorder = woSet.add();
} else { // update
SqlFormat sqf = new SqlFormat("WORKORDERID = :1");
sqf.setObject(1, "WORKORDER", "WORKORDERID", WORKORDERID);
woSet.setWhere(sqf.format());
woSet.reset();
workorder = woSet.getMbo(0);
}
workorder.setValue("DESCRIPTION", DESCRIPTION);
workorder.setValue("OWNER", OWNER);
woSet.save();
callback.execute("{ \"uniqueId\": \"" + workorder.getUniqueIDValue() + "\" }");
Avoid SQL Injection¶
The method MboSet.setWhere(String query)
should not be invoked with concatenated strings such as
"wonum = '" + wonum + "' and siteid = '" + siteid + "'"
since this brings the risk of SQL Injection.
Instead, the construct psdi.mbo.SqlFormat
should be used:
import psdi.mbo.SqlFormat;
var sqlf = new SqlFormat("wonum = :1 and siteid = :2");
sqlf.setObject(1, "WORKORDER", "WONUM", wonum);
sqlf.setObject(2, "WORKORDER", "SITEID", siteid);
var whereClause = sqlf.format();
someMboSet.setWhere(whereClause);