Question

Bug: Duplicated lookups are inserted in to the detail when using MultiChoice add-on

Hi All, 

 

We noticed a bug in the add-on MultiChoice. The process to replicated the issue is following:

Bug-1:

  1. Configure one multi-choice combobox on any page.
  2. Select 2 values from the list and save it. 

    So far, in the database there are only two entries in the detail as you are expected.
  3. Do not close the page and add extra 4 lookup from the list and save it.

    Now, in the database there are 8 records in the detail instead of 6. The first 2 lookup I selected were duplicated.
  4. After that the Combobox does not work anymore. no matter what you do (delete, select new entry) will not be saved anymore.

Bug-2:

  1. Configure the lookup value from the above example. Ensure you have tow lookup with the same value your lookup table.
  2. On the page, select the two values which are duplicated in the list.
  3. Do not close the page, and remove 1 value from the list and save the page.
  4. You will see the value is removed from UI. But it is still in the database. If you reload the page, the remove record will show again on the UI.
  5. Reload the page, and remove 1 value. This time you will see it has been removed.

For the bug-1, I use a business process to double check if there a duplicates. It is not the best solution, but it works.

 

Is there anyone who has the same experience?

 

best regards,

 

Cheng Gon

Like 1

Like

3 comments
Best reply

I do get the same issue, I just had not noticed this behavior until I read your post and tested it. The issue is that the code expects that onSaved (after the save) you've left the page and all gets destroyed instead of modifying the collections used with the updated/deleted items.

As a temporary solution/fix, you can add this to the page where the MultiChoice component is used: 

updateMultiChoiceRecords: function() {
	if (!this.$IsNeedToUpdateMultiChoice) {
		return;
	}
	const items = this.getMultiChoiceEntitiesConfig();
	const batch = this.Ext.create("Terrasoft.BatchQuery");
	this.Terrasoft.each(items, function(config, columnName) {
		this.addDeleteQuery(config, columnName, batch);
		this.addInsertQuery(config, columnName, batch);
	}, this);
	this.$IsNeedToUpdateMultiChoice = false;
	batch.execute(function() {
		this.loadMultiChoiceColumns(this);
	}, this);
}

Really, all we need is to be able to execute the loadMultiChoiceColumns function in the callback from the batch execute, however, there's no other way to do it other than replace the entire updateMultiChoiceRecords function from the MultiChoiceMixin. You'll get a quick flicker on save since this recreates the collections of items initially bound to the control  - ideally you'd just read the response from the batch and just add the inserted objects and remove the deleted only. But for now it will at least fix the behavior. I didn't do that in the above since it's easier to just reload the collections - hopefully the devlabs team will see this and release a proper fix.

Ryan

I do get the same issue, I just had not noticed this behavior until I read your post and tested it. The issue is that the code expects that onSaved (after the save) you've left the page and all gets destroyed instead of modifying the collections used with the updated/deleted items.

As a temporary solution/fix, you can add this to the page where the MultiChoice component is used: 

updateMultiChoiceRecords: function() {
	if (!this.$IsNeedToUpdateMultiChoice) {
		return;
	}
	const items = this.getMultiChoiceEntitiesConfig();
	const batch = this.Ext.create("Terrasoft.BatchQuery");
	this.Terrasoft.each(items, function(config, columnName) {
		this.addDeleteQuery(config, columnName, batch);
		this.addInsertQuery(config, columnName, batch);
	}, this);
	this.$IsNeedToUpdateMultiChoice = false;
	batch.execute(function() {
		this.loadMultiChoiceColumns(this);
	}, this);
}

Really, all we need is to be able to execute the loadMultiChoiceColumns function in the callback from the batch execute, however, there's no other way to do it other than replace the entire updateMultiChoiceRecords function from the MultiChoiceMixin. You'll get a quick flicker on save since this recreates the collections of items initially bound to the control  - ideally you'd just read the response from the batch and just add the inserted objects and remove the deleted only. But for now it will at least fix the behavior. I didn't do that in the above since it's easier to just reload the collections - hopefully the devlabs team will see this and release a proper fix.

Ryan

Ryan Farley,

Thanks for the solution here. Just implemented your suggestion and it works perfectly.  Both of 2 bugs has been solved once we reload the collections after saving.

Ryan Farley,

 

Hello Ryan!



Thank you for your solution. We tested it on our end and implemented it in the add-on.

Show all comments