Create Related Entity from Parent Browse Screen

I am trying to create an associated entity from the browse screen of the parent entity. I have an entity, Activity, which is the parent entity has many Contact Attempt entities associated. I want to be able to create a Contact Attempt for the Activity from the browse screen. I can do it easily from the Activity edit screen, but cannot seem to figure out how to launch the create action for the related.

Any help you can provide would be greatly appreciated.

Hi Vincent,

You can use the openEditor() method in Activity browser screen: create an instance of ContactAttempt, set the selected Activity to this instance, and pass this instance as a parameter for the ContactAttempt editor:

if (activitiesTable.getSingleSelected() != null) {
    ContactAttempt contactAttempt = metadata.create(ContactAttempt.class);
    contactAttempt.setActivity(activitiesTable.getSingleSelected());
    openEditor("demo$ContactAttempt.edit", contactAttempt, WindowManager.OpenType.DIALOG, ParamsMap.of("attemptWithActivity", contactAttempt));
}

Then, in ContactAttempt editor, use this parameter, for example:

if (params != null) {
    ContactAttempt attempt = (ContactAttempt) WindowParams.ITEM.getEntity(params);
    setItem(attempt);
};

I’ve attached a small sample project with this approach working: demo.zip (84.3 KB)

2 Likes

Olga,
That’s great! I figured it out just before you responded. I went digging into the code for CreateAction and EditAction and found the information. Thanks for your response.

Thanks,
Vincent

1 Like