Adding a new row to another table using java in Ma

2019-09-06 10:12发布

问题:

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.



标签: java maximo