Issue Clearing Datasource

Hi, I’m trying to clear a nested datasource, but it’s not working as expected.
The datasource is populated based on user selection.
But when I use the standard clear function, the datasource remembers the items that need to be committed.

I did some debuggin and there is a property: itemsToCreate. This does not get cleared with ds.clear().

 <datasource id="salesProcInvoiceDs"
		class="com.company.entity.Invoice"
		view="invoice-edit-view">
<collectionDatasource id="invoiceDetailLinesDs"
					  property="invoiceDetailLines"/>
public void setDetails(Invoice invoice){// Function gets called after a property change listener.

//1. Clear data source commit list (this is temporary workaround)
((AbstractDatasource) invoiceDetailLinesDs).clearCommitLists();

//2. CLear entity list
if(invoice.getInvoiceDetailLines()!=null)
	invoice.getInvoiceDetailLines().clear();

//3. Clear data source
invoiceDetailLinesDs.clear();

if(invoice.getReceipt() != null) {

	Receipt receipt = receiptService.getById(invoice.getReceipt().getId().intValue());

	// add details from Receipt
	List<ReceiptDet> receiptDetails = receipt.getReceiptDetails();
	for (ReceiptDet receiptDet :receiptDetails) {
		InvoiceDet invoiceDet = metadata.create(InvoiceDet.class);
		invoiceDet.setInvoice(invoice);
		invoiceDet.setAmount(BigDecimal.ZERO);
		invoiceDet.setAmount(BigDecimal.ZERO);
		invoiceDet.setQty(receiptDet.getQty());
		invoiceDetailLinesDs.addItem(invoiceDet);
	}
}

Method 2 + 3 don’t clear the Datasource property itemsToCreate.
If I do invoiceDetailLinesDs.getItems() it does say 0 items, but itemsToCreate just keeps increasing. And when commiting it tries to save all the items.

Is this expected behaviour?
With method 1 I got it working, but is it the right way?

Side Note:In this case the user can only change the parameters as long as the item isn’t saved.
Using platform 6.6.3

Hi Renato,

Historically, neither CollectionPropertyDatasourceImpl nor CollectionDatasourceImpl clear commit lists on clear() invocation. This is even declared in the CollectionDatasource JavaDoc: “The datasource “modified” state doesn’t change.” So we cannot change this behavior now.

I would suggest using your first method, but casting to an interface:

((DatasourceImplementation) invoiceDetailLinesDs).clearCommitLists();

I understand that API is not nice. We are going to improve it in the future major feature release.

Hi, I have similar Issue. (Platform Release 6.10.17)

        // If Some Items exist clear
        if (feesDs.getItems() != null) {
            feesDs.clear(); <<<<<<<<<<<<<<<<<<<<<< I tried also different soutions provided, also 
              solution provided but with no success!!! I disable also Database constraint 

create unique index IDX_CONTACTS_MEMBERSHIP_FEE_UNQ on CONTACTS_MEMBERSHIP_FEE (YEAR_N, PERSON_ID) where DELETE_TS is null ^

but old items persist, with constraint I have a duplicate item error.


        }


        // Add MembershipFees Array if not present
        if (feesDs.getItems() == null) { // Empty Fees
            List<MembershipFee> membershipFees = new ArrayList<>();
            p.setMembershipFees(membershipFees);
        }

        for (int i=0;i<max_all_fee;i++) {

            // Generate and Add MemberShip Fee  ------------------------------------------------------------------
            MembershipFee f = metadata.create(MembershipFee.class);

            // Links
            f.setPerson(p);
            p.getMembershipFees().add(f);
            feesDs.addItem(f);

            // Initialize
            if (i==0) { // First Year
                f.setStartDate(start_date);
                f.setDueDate(J8d.plusDays(fee_pay_days_first,start_date));

Logic is really simple but evidently deleting ops are not passed for committing in DSContext.
I use Soft Delete if this can be usefull.

Thanks in advance,
Fabrizio