Remove Duplicates from Auto-Suggest control

Comments

1 comment

  • Avatar
    Krishna Kumar R

    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 executed
    options.lookupType = eFormHelper.constants.lookuptype.namevalue; // Name/Value lookup type
    eFormHelper.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 array
                return 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
    0
    Comment actions Permalink

Please sign in to leave a comment.