Auto Complete in Dynamics CRM

Following is sample JavaScript code to demonstrate the auto completion feature. This sample configures the auto-complete feature for a custom single line of text that auto complete years.



Call following function on form load event, this will auto populate the last 60 years in the field when do keypress on this field.

function year_AutoComplete() {
    var keyPressFcn = function (ext) {       
        try {           
            resultSet = {
                results: new Array()                
            };
            var dt = new Date();           
            for (i = 0; i < 50; i++) {               
                    resultSet.results.push({
                        id: i,
                        fields: [dt.getFullYear() - i]
                    });                           
            }         

            if (resultSet.results.length > 0) {
                ext.getEventSource().showAutoComplete(resultSet);
            } else {
                ext.getEventSource().hideAutoComplete();
            }
        } catch (e) {          
            console.log(e);
        }
    };
   
    Xrm.Page.getControl("new_year").addOnKeyPress(keyPressFcn);
}

Comments

Popular posts from this blog

Mastering Dynamics 365 Plugin Development: A Complete Step-by-Step Guide

Dynamically Populating Ribbon Flyout Menu in Unified Interface

Dynamically Populating Ribbon Flyout Menu