vijet
Jr. Member

Karma: 5
Posts: 56
|
 |
« on: August 12, 2008, 08:02:42 am » |
|
Hi,
My requirement is as follows....
I have to calculate the result of the values entered in one filed as and when entered and then set the calculated value to another field in another MBO..... I was able to implement the code to set the calculated value on save but not as and when entered.... Is there any method by which i can do this dynamically....
Example
Some cost is entered in a field....... (This can be changed frequently by adding new row) say 100 200 300
I have a field in the same screen but in another MBO say "total of the costs"
I want to set the values to the total cost field whenever the new cost is updated.....(before the save)
Thanks Vijet
|
|
|
|
|
Logged
|
|
|
|
|
amdisuk
|
 |
« Reply #1 on: August 12, 2008, 08:13:56 am » |
|
Yes you can create a custom validation class and ad your code to set the value in the other table on the fly.
Al
|
|
|
|
|
Logged
|
Big Al
|
|
|
vijet
Jr. Member

Karma: 5
Posts: 56
|
 |
« Reply #2 on: August 12, 2008, 08:37:53 am » |
|
Hi , Thanks for the reply... Could you please be more elaborate.... Newbee to JAVA too....... 
|
|
|
|
|
Logged
|
|
|
|
|
amdisuk
|
 |
« Reply #3 on: August 12, 2008, 09:06:49 am » |
|
Have a look at an existing field that has a custom class associated with it. I can't remember what the custom classes extend from (and alas, I don't have a Maximo instance with me).
I hope that you have exposure to customizing Maximo java classes?? If not then you will have a steep learning curve (but not impossible).
Basically you can create java classes that run custom code to validate your entries and perform lookups etc.
Al
|
|
|
|
|
Logged
|
Big Al
|
|
|
|
maurogrz
|
 |
« Reply #4 on: August 12, 2008, 09:17:35 am » |
|
in the field level class you can get the related Mbo and then let him compute its "total cost". ..... field level class ..... public void action() throws MXException, RemoteException { Mbo currentMbo = (Mbo) getMboValue().getMbo(); Mbo ownerMbo=(Mbo)currentMbo.getOwner(); ownerMbo.computeTotal(); } .....
..... mbo level class ..... public void computeTotal() throws MXException, RemoteException { //use your logic to compute the new total (as for the save() method) } .....
if you are absolutely new in Java and Maximo customization with classes, I can sugget you to get the documetation of the Developer Reference Giude from the support site and have a look to it before !
|
|
|
|
|
Logged
|
|
|
|
vijet
Jr. Member

Karma: 5
Posts: 56
|
 |
« Reply #5 on: August 12, 2008, 04:16:17 pm » |
|
Hi Guys,
Thanks a lot for the sggessions... i was able to implement the logic...... now the issue is that when i change the cost or value for the first time the field gets dynamically updated but it does not happen the second time... i will have to explicitly save the value for the total cost to reflect... The cost gets stored in database but is not reflected on screen before the save.... is there any method by which i can refresh the page with the new calculated value....
Thanks Vijet
|
|
|
|
|
Logged
|
|
|
|
|
maurogrz
|
 |
« Reply #6 on: August 12, 2008, 05:38:51 pm » |
|
it is quite strange..... did you try to debug or to see if there are errors in the log file ?
|
|
|
|
|
Logged
|
|
|
|
|
amdisuk
|
 |
« Reply #7 on: August 13, 2008, 06:20:48 am » |
|
Can you post your code?
Sounds like you are not setting the correct instance of your Mbo.
Al
|
|
|
|
|
Logged
|
Big Al
|
|
|
vijet
Jr. Member

Karma: 5
Posts: 56
|
 |
« Reply #8 on: August 13, 2008, 07:18:55 am » |
|
Here is the code...............MboRemote mbo = (ComponentsMBO)getMboValue().getMbo(); System.out.println("mbo returned is...."+mbo); int sum =((ComponentsMBO) mbo).computeTotal(); System.out.println("sum is...."+sum); String piDocNo = mbo.getString("PIDOCNUMBER"); MboRemote versionRecord1 =getMboValue().getMbo().getOwner(); String desgnopt = versionRecord1.getString("DESIGNOPTIONID"); System.out.println(desgnopt+"design id................++++++"); String sWhere = "PIDOCNUMBER = '"+piDocNo+"' and DESIGNOPTIONID = '"+desgnopt+"'"; MboSetRemote result = getMboValue().getMbo().getMboSet("REFDESIGNOPTNID", "SPR_MP_DESIGNOPTNS", sWhere); System.out.println(result.count()+"count of the design option id.............."); MboRemote CompRecord =result.getMbo(0); System.out.println(CompRecord+"After Count before setting value................."); String setval = Integer.toString(sum); System.out.println(setval+"Setvalue................."); CompRecord.setValue("COSTSUMMARY", setval); System.out.println("after costsummary set....................."); result.save();
|
|
|
|
« Last Edit: August 13, 2008, 07:45:00 am by amdisuk »
|
Logged
|
|
|
|
|
amdisuk
|
 |
« Reply #9 on: August 13, 2008, 07:49:00 am » |
|
OK, I think the problem is in this line MboSetRemote result = getMboValue().getMbo().getMboSet("REFDESIGNOPTNID", "SPR_MP_DESIGNOPTNS", sWhere);
The record that you are updating is not in the same transaction as the records that display the screen. Is there a relationship between "REFDESIGNOPTNID" and the owner? If not then you will have to create one. Maybe I'm not so clear. For the screen details to update you have to update records that are related to the one used to display the screen. Hope that helps. Al
|
|
|
|
|
Logged
|
Big Al
|
|
|
|
amdisuk
|
 |
« Reply #10 on: August 13, 2008, 07:51:39 am » |
|
Incidentally (as you stated that you are new to java), java instance names always start with a lower case letter and any subsequent words with an upper case letter. For example : MboRemote CompRecord =result.getMbo(0); Should be MboRemote compRecord =result.getMbo(0); It's a small thing but is important to java programmers. 
|
|
|
|
|
Logged
|
Big Al
|
|
|
vijet
Jr. Member

Karma: 5
Posts: 56
|
 |
« Reply #11 on: August 13, 2008, 09:14:00 am » |
|
Here is the code after using relationship.......
MboRemote mbo = (ComponentsMBO)getMboValue().getMbo(); if(mbo instanceof ComponentsMBO) { int sum =((ComponentsMBO) mbo).computeTotal(); System.out.println("sum is...."+sum); MboSetRemote desgnoptset=mbo.getMboSet("COMP2DESIGN"); /* This is the relation between the result and owner....*/
MboRemote compRecord =desgnoptset.getMbo(0); String setval = Integer.toString(sum); System.out.println(setval+"Setvalue................."); compRecord.setValue("COSTSUMMARY", setval); /* On first change the costsummary is updated and value is also saved in database but on second change the record is saved in database but not reflected on screen......... */ System.out.println("after costsummary set....................."); desgnoptset.save(); System.out.println("after save.....................");
It is doing the same thing .. not reflecting the change on screen for second change in value.... but the value gets updated if the save button is clicked...........
|
|
|
|
|
Logged
|
|
|
|
|
maurogrz
|
 |
« Reply #12 on: August 13, 2008, 09:58:47 am » |
|
if you are in a master/detail situation, why not use the getOwner avoiding the use of the relation ?
instead of MboSetRemote desgnoptset=mbo.getMboSet("COMP2DESIGN"); MboRemote compRecord =desgnoptset.getMbo(0);
try using MboRemote compRecord=mbo.getOwner();
and probably the desgnoptset.save(); is not necessary
|
|
|
|
|
Logged
|
|
|
|
|
amdisuk
|
 |
« Reply #13 on: August 13, 2008, 10:06:33 am » |
|
Ok,
Try saving
getMboValue().getMboSet().save();
I think you will need to save the set that controls the application (the main set). That may trigger the refresh of the screen. It will also save the changes for any related records including the one you changed.
Hope this works!!
Al
|
|
|
|
|
Logged
|
Big Al
|
|
|
|
amdisuk
|
 |
« Reply #14 on: August 13, 2008, 10:08:12 am » |
|
if you are in a master/detail situation, why not use the getOwner avoiding the use of the relation ?
Yes this is the best approach. I didn't understand the relationships! Al
|
|
|
|
|
Logged
|
Big Al
|
|
|
|