cont.......
7.Now code sniplets
1.set statdate to current date in non-persistent main class’s add method
public void add()
throws MXException, RemoteException
{
super.add();
Date currentDT = MXServer.getMXServer().getDate();
setValue("statdate", currentDT, 11L);
}
Now in set class of non-persistent object write similar code
protected MboSetRemote getMboIntoSet(MboRemote mbo)
throws MXException, RemoteException
{
MboSetRemote changeSet = getMboServer().getMboSet("XREQUISITION", getUserInfo());
SqlFormat sqf = new SqlFormat(mbo, "xid = :xid and siteid = :siteid");
changeWOSet.setWhere(sqf.format());
return changeSet;
}
protected void changeMboStatus(MboRemote req, MboRemote param)
throws MXException, RemoteException
{
((RequisitionRemote)req).changeStatus(param.getString("status"), param.getDate("statdate"), param.getString("memo"));
}
Our Remote must contain changeStatus method so create it in Remote.
Methods to be used in CustomStatusHandler class
public void canChangeStatus(String currentStatus, String desiredStatus, long accessModifier)
throws MXException, RemoteException
{
Current status and desired status are available here so any conditions needed to be checked before the status can be changed can be done here.Exceptions can be thrown.
}
public void changeStatus(String currentStatus, String desiredStatus, Date date, String memo)
throws MXException, RemoteException
{
In this method we can apply status changes to main object attributes.
Parent.SetValue(“status”,desiredStatus.2L)
}
After this method is done the controll goes to Main Class which also has a changeStatus() method
public void changeStatus(String status, Date date, String memo,
long accessModifier) throws MXException, RemoteException {
Now set values to xstatushistory
SqlFormat sqf = new SqlFormat("1=2");
MboSetRemote statusHistorySet = getMboSet("&statushistory",
"xstatushistory", sqf.format());
System.out.println("mbo set is" + statusHistorySet.getName());
MboRemote historyStatusRemote = statusHistorySet.add();
if (historyStatusRemote != null) {
historyStatusRemote.setValue("xid", getString("xid"), 2L);
historyStatusRemote.setValue("xchangeby",
getString("xchangedby"), 2L);
historyStatusRemote.setValue("statdate",
getString("xchangedate"), 2L);
historyStatusRemote.setValue("status", status, 2L);
historyStatusRemote.setValue("memo", memo, 2L);
}
This should give u status change functionality ........................
StatusHandler methods call flow
Its starts when u select the Change Status option in Select Actions
For easier understanding i am using the names of class files in my application along with the object names.
Object : Xrequisition ----main class Requisition.java (req or requisition)
-----ReqStatusHandler.java
Xstatushistory ----- ReqStatus.java
Xstatus [non-persistent] ----ReqChangeStatus.java and ReqChangeStatusSet.java
1. in ReqChangeStatusSet getMboIntoSet()
2. in req constructor()
3. in req init()
4. in ReqChangeStatusSet changeMboStatus()
5. in requisition changeStatus ()
6. in requisition getStatusListName()
7. in requisition getStatusHandler()
8. in ReqStatusHandler constructor()
9. in ReqStatusHandler canChangeStatus()
10. in requisition changeStatus ()
For more ref plz check PR application class files.
Hope it helps u
Thanks & Regards
