Adding a new row to another table using java in Maximo

妖精的绣舞 提交于 2019-12-13 04:48:38

问题


I have two tables that I'm working with: KINCIDENT and ASSISTANT. The main one is KINCIDENT and the two are linked using an ID. I'm able to add a new row from the application but I want to do this using Java. I tried the following code but did not work:

MboSetRemote assistSet = MXServer.getMXServer().getMboSet("ASSISTANT",userInfo);
MboRemote newAssist = assistSet.add();
newAssist.setValue("LOCATION",x);
newAssist.setValue("INCNUM",y);
assistSet.save();

I checked to see if the row was added but it wasn't and I also didn't find any new entries in the database either. Am I missing something?


回答1:


As long as your code is running, you should have seen that new record in the assistant table, but you definitely would not have seen that on the screen. To make the record appear on the screen, you have to know Maximo's "cache" system to get and edit the exact instance of the set that backs the screen, instead of just any instance (or a whole new instance like you created there).

I don't know where your Java code is (an app bean, an MBOSet, an MBO, or a field class) and I don't know what event/trigger you are hooking into (adding a new record, saving an existing record or something else), both of which are important to know. I will assume you are in an MBO class of the KINCIDENT object running in the "add()" method; meaning when a new KINCIDENT is created, you want to add a new ASSISTANT record. Running as part of that trigger should mean that you are already hooked into the screen instance of the KINCIDENT object when a user adds a new record. To make your ASSISTANT record appear in the set instance backing the screen, you need to the follow the screen's relationships from KINCIDENT to ASSISTANT. I'm assuming on the screen the ASSISTANT table is set up as a child of the KINCIDENT table using a relationship. In that case you just need to get the ASSISTANT set using that relationship. Assuming your relationship is named the same as the set ("ASSISTANT"), it would look something like this:

MboSetRemote assistSet = getMboSet("ASSISTANT");
MboRemote newAssist = assistSet.add();
newAssist.setValue("LOCATION",x);
newAssist.setValue("INCNUM",y);

This will not save your record yet (persist it to the database), but you want to keep your saves to a minimum. Let the user specify if a record should be saved or not by them hitting the "save"/disk icon in the toolbar.



来源:https://stackoverflow.com/questions/27763701/adding-a-new-row-to-another-table-using-java-in-maximo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!