The error you are receiving is a valid Maximo error given what you are trying to do. The logic is that if the current status of the asset is DECOMMISSIONED and the RETURNTOVENDOR flag is true then you are going to get that error. You could avoid that by setting the RETURNTOVEDOR flag to false or by forcing the status to something other than DECOMMISSIONED before you run the transaction, but both of those may not have other ramifications, depending on what you are doing.
There are a number of other minor problems with the code you provided so I have gone ahead and rewritten it with comments to explain the differences.
Since you are going from Java 7 to Java 8 you might want to look at:
https://www.sharptree.io/blog/2021/2021-10-28-js-nashorn-vs-rhino/If you have any questions feel free to reach out.
- Jason
// Here is how to do this in Nashorn without the compat library
MXServer = Java.type("psdi.server.MXServer");
// structure so you an return properly.
main();
function main() {
//if you are going to check if the Mbo is null do it early otherwise calling getUserInfo() is going to throw an exception
if (typeof mbo !== 'undefined' && mbo && mbo.getMboValue("RETURNEDTOVENDOR").isModified() && mbo.getBoolean("RETURNEDTOVENDOR")) {
// get the asset set from the mbo without having to fetch it separately
var woAssetSet = mbo.getMboSet("$relatedasset", "ASSET", "assetnum = :assetnum and siteid =:siteid")
// check if the returned set has any records.
if (!woAssetSet.isEmpty()) {
woAssetMbo = woAssetSet.getMbo(0);
// Note the parameters here. The first is the new location, which "RETURN ASSET TO VENDOR" seems more like the memo
// moveAssetWithinInventory(String newLocation, String memo, Date dateMoved, String newBinnum, String ponum, String glCreditAcct, String glDebitAcct, String matRecTransID);
woAssetMbo.moveAssetWithinInventory("NEWLOCATION","RETURN ASSET TO VENDOR", MXServer.getMXServer().getDate(), "", "", "", "", "");
woAssetMbo.changeStatus("RETURN", false, true, true, true);
// no need to save, because the woAssetMbo is part of the current transaction and will be saved when the transaction saves.
}
}
}