Remove Duplicates from Auto-Suggest control
I have an auto-suggest control on my eForm that points to an AgilePoint Data Entity and pulls from the "Filename" field, which can have duplicate values. I was wondering if there was a way to remove the duplicates from the auto-suggest field.
I have an auto-lookup control that takes the the resulting filename selected from the auto-suggest control, and displays all records with that filename in a subform. So the subform will show me all the records using the selected filename. Therefore, I do not need to see duplicates in the auto-suggest control.
-
Hello Brad,
The Auto-Suggest control doesn't inherently support removing duplicate records fetched from an external data source. However, you can customize this using JavaScript by leveraging the executeLookup eFormHelper method, along with logic to filter out duplicates from the response received from the lookup. Finally, you can bind the filtered response data to the Auto-Suggest control using the bindDataToCollectionControls eFormHelper method.
Here's how:
function bindDataToCollectionCtrl(dataSet) {var options = {};options.fieldId = 'AutoSuggest1'; //Specify the collection control name.options.value = dataSet; //Specifies the value as an array of objects as name/value pair.
eFormHelper.bindDataToCollectionControls(options, function (result) {if (result.isSuccess) //Checks if the method completes successfully and returns a response.{console.log(result.data); //Logs the data and displays an array of variable names and values.}else {console.log(result.error); //Logs the error and error description, if any.}});}
var options = {};options.lookupName = 'testAutoLookup1'; // Provide the lookup name that has to be executedoptions.lookupType = eFormHelper.constants.lookuptype.namevalue; // Name/Value lookup typeeFormHelper.executeLookup(options, function (result) {if (result.isSuccess) {var duplicateRecordsArr = result.data;var uniqueRecordsArr = duplicateRecordsArr.filter((obj, index) => {// Use findIndex to check if the current object is the first occurrence in the arrayreturn index === duplicateRecordsArr.findIndex((item) => (item.Name === obj.Name && item.Value === obj.Value));});bindDataToCollectionCtrl(uniqueRecordsArr);}else {console.log(result.error); // logs the hold exception object}});Hope this helps.Thank you
サインインしてコメントを残してください。
コメント
1件のコメント