Edit screen asking to save changes every time I click cancel button

I have an edit screen for my Entity HrUser. This Entity has related Entities of type ServiceRequest.
When I open my screen I have 3 Tabs:
HrUser object details
ServiceRequest list,where I can create, modify and delete related Service Requests
History: Where I see all changes made in HrUser objects as well as in related ServiceRequest objects

Since the query to get the history can be quite complex I load the history in my onAfteShow event

       String query = hrUserService.getEntityLogQuery(getEditedEntity());

       // Query can be like this: 
       // select el from sec$EntityLog el where el.entity = 'userlifecyclemgmt_HrUser' and el.entityRef.entityId = '81b81444-0444-4ff0-c409-64393be41140' or el.entity = 'userlifecyclemgmt_ServiceRequest' and el.entityRef.entityId = '7b8c27c1-41e8-53f3-d94c-c15b865c4bfa' 

That works fine, but the last line loading the collection causes the screen to ask to save changes, when I use the cancel button instead of just closing.
When commenting the line out, the screen just closes.

Question now would be: How can I tell my screen to ignore the changes in that collection

       <collection id="entityLogDc" view="entityLogItem-view" class="com.haulmont.cuba.security.entity.EntityLogItem">
            <loader id="entityLogDl">
                    <![CDATA[select l from sec$EntityLog l where l.entityInstanceName = 'fake name']]>
            <collection id="entityLogAttributes" property="attributes"/>

The issue is caused by the fact that EntityLogAttribute is a transient entity which is always recognized as New, so when it is loaded into the screen’s DataContext in the AfterLoad event the screen decides it has changes. There is hasUnsavedChanges() method in StandardEditor which makes that decision. You can set a breakpoint into its default implementation to investigate what’s going on, or to override it in your screen controller.

A simple workaround in your case is to clear the flag about changes right after loading the problematic entities:

public void onAfterShow(AfterShowEvent event) {
    // ...


setModifiedAfterOpen(false); does exactly what I need it to do. Great! Thanks very much! Definitely a method that may come in handy at some other scenario. :slight_smile: