Entity vs datasource

Hi,

I have the next code (in PaymentEdit screen, Transaction - Payment = Many-to-many association):

       lookupPickerField.addValueChangeListener(e -> {          
            Transaction t = e.getValue();
            if (t != null) {
                transactionsDs.addItem(t);
                t.setActive(false);
                t.setStatus(TransactionStatusEnum.Paid);
//                transactionsDs.getItem().setActive(false);
//                transactionsDs.getItem().setStatus(TransactionStatusEnum.Paid);
             
            }
        });

Why

t. works and transactionsDs.getItem() doesn’t work?

Because CollectionDatasource.addItem() adds an instance to the collection, but it doesn’t set it as the “current” item. While getItem() returns the current instance. If you want to set the current item, call setItem() after adding.

Thank you very much, Konstantin!