Maximo List Archive

This is an archive of the Maximo Yahoo Community. The content of this pages may be a sometimes obsolete so please check post dates.
Thanks to the community owner Christopher Wanko for providing the content.



Custom Action to add new records

From: Radu (2011-09-28 12:23)

Hello All!
I am new to java development and i have the following task to complete:
When a PO is approved and the lines copied from PR are with lower quantities than the one's in PRLINE i should create a new PR with the remaining quantities.
I tried the following code but with no success. Can someone point me in the right direction?
package psdi.common.action;
/**
* @author rdragomir
*/
import java.io.*;
import java.rmi.RemoteException;
import psdi.mbo.*;
import psdi.server.MXServer;
import psdi.util.MXApplicationYesNoCancelException;
import psdi.util.*;
import psdi.app.pr.*;
import psdi.app.po.*;
public class custCreatePRAction
implements ActionCustomClass
{
public void applyCustomAction(MboRemote mboremote, Object aobj[])
throws MXException, RemoteException
{
PORemote poMbo = (PORemote)mboremote; // PO object
POSetRemote poObj = (POSetRemote)poMbo.getThisMboSet(); // PO set
POLineSetRemote poLines = (POLineSetRemote)poMbo.getMboSet("POLINE"); // POLine set
int linii = poLines.count();

if (linii > 0) {
for (int i=0;i<linii;i++) {
POLineRemote poLine = (POLineRemote)poLines.getMbo(i); // POLine object
PRLineSetRemote prLines = (PRLineSetRemote)poLine.getMboSet("PRLINE"); // PRLine set
if (!prLines.isEmpty()) {
PRLineRemote prLine = (PRLineRemote)prLines.getMbo(0); // PRLine object
PRSetRemote prObj = (PRSetRemote)prLine.getMboSet("PR"); // PR Set
if (prLine.getDouble("orderqty") - poLine.getDouble("orderqty") > 0) {
PRRemote oldPR = (PRRemote)prLine.getMboSet("PR").getMbo(); // Old PR object
PRRemote newPR = (PRRemote)prObj.add(); // New PR object
newPR.setValue("description", oldPR.getString("description"));
newPR.setValue("internal", true);
newPR.setValue("storeloc", oldPR.getString("storeloc"));
prObj.save();
PRLineSetRemote newPRLines = (PRLineSetRemote)newPR.getMboSet("PRLINE");
PRLineRemote newPRLine = (PRLineRemote)newPRLines.add();
newPRLine.setValue("itemnum", prLine.getString("itemnum"));
newPRLine.setValue("orderqty", prLine.getDouble("orderqty") - poLine.getDouble("orderqty"));
newPRLine.setValue("storeloc", prLine.getString("storeloc"));
newPRLines.save();
}
}
}
}

}
}
Thank you,
Radu.