How to save other tabs records from the same editor screen

SaveTabsApp.zip (1.8 MB)

Hi,

I am getting problem with saving other tabs records from the editor screen.
For ex:- When I “clone” (button in underwritersins browser screen) any record , it will copy all the record from all tabs in the editor screen but when I save it it wont save other tabs record except first one.
Attached is the sample project where below one is the screen which I am referring:
Could anyone please help me out.

image

Thanks,
Saurabh

Hi Saurabh,
Please provide a small test project demonstrating your problem. Use HSQL database and create some test data in it. Use zipProject Gradle task to zip the project together with the database.

Hi Konstantine,

sample-workshop-master.zip (4.8 MB)

Note: In this project only two entity has been used for sample -> Client & Mechanics

I have some changes in Workshop project for sample. There are 2 things which creating issue…

1- In the project , when we edit client’s screen we can see a tab below (Mechanic’s entity)
Now When I select any record and press ‘cone’ button it will copy some fields but when we save the record that tab’s record will not save if we change anything in it.
for ex: tab has a field ‘hourly rate’ , if you edit it and save it , it wont reflect.

2- Also in the client entity there is one field ‘clientId’ , and in the Mechanics entity there is one field ‘clientSubId’. I want first ‘clientId’ should generate while edit, and then copy that newly generated ‘clientId’ to ‘clientSubId’ in the tab. .

Thanks,
Saurabh

Although I don’t see the point in showing the full list of Mechanics in the Client editor, your case 1 works for me: changes in the Mechanics table a saved when I save the editor.

Regarding 2, do you really want to update all mechanics every time you create a client? Probably you need to use nested datasources and load mechanics linked to the client.

Hi Konstantine,

It will save record when we go by ‘create’ button. But here my issue with ‘clone’ button.
Regarding 2, Its not necessary to clone all mechanics field, but by clone feature we can decide which field we can edit and which not.

In a simple way, I want to clone the record row from the client browse screen. So in Client edit screen all fields were copied,now I want to edit some fields. After edit done I want to save the record. Also I want to save edited tab records.
Also subId in mechanics (foreign key with ID in client screen) is related with ID, subId should should be mapped with newly generated ID while cloning.
I dont know if I am clear about issue here but everything is to do with “clone” button and saving record of tabs field.

Regards,
Saurabh

Hi Saurabh,

I suppose that you want to clone an entity with a linked collection. What if we consider it on Order - OrderLines entities from the QuickStart / Sales example?

Hi Konstantine,

saveTabs.zip (750.6 KB)

I think very good way to understand this is with the same project I am working on. So I have created a new sample project with HSQL db. (Attached)

Below are the steps which expose the issue better:-

1- There are two screen i.e., UnderwritersIns & GrsIndustries
2- Under browse screen UnderwritersIns , there is a ‘clone’ button , when we select any record and do ‘clone’. you will get the edit screen with copied record in both of the tabs.
3- Now lets say we need to edit few fields i.e., FirstName & LastName. Rest of the record are same including both tabs.
4- When we save the record after edit done, a new row (record) will be created. Now when we go to see if everything copied successfully with ‘edit’ button. You can see only first tab record are saved not second one (GRSIndustries).

I hope this one gives a clear shot for the stuck flag.

Thanks,
Saurabh

Hi Saurabh,

In onCopyBtnClick method you create a copy of the current entity and open an edit screen for it. So create also copies of the nested object and add them to the collection:

newUnderwritersIns.setGrsIndustries(new ArrayList<>());

LoadContext.Query query = LoadContext.createQuery("select e from loa$GRSIndusIns e where e.subID.id = :param")
        .setParameter("param", underwritersIns);
List<GRSIndusIns> grsIndusIns = dataManager.loadList(LoadContext.create(GRSIndusIns.class)
        .setQuery(query).setView("GRSIndusIns-screen-view"));
for (GRSIndusIns grsIndusIn : grsIndusIns) {
    GRSIndusIns grsIndusIns1 = metadata.create(GRSIndusIns.class);
    grsIndusIns1.setIndustry(grsIndusIn.getIndustry());
    grsIndusIns1.setSubID(newUnderwritersIns);
    newUnderwritersIns.getGrsIndustries().add(grsIndusIns1);
}

openEditor(newUnderwritersIns, WindowManager.OpenType.THIS_TAB).addCloseWithCommitListener(() -> underwritersInsesDs.refresh());
1 Like

Thank you Konstantin. It worked for me perfectly.