In earlier article we discussed about new scripting methods introduced in CRM 2016 to implement AutoComplete feature. In last example we used hard coded option to show over autocomplete list, but in this post we are going to demonstrate how we can bring these options from a custom configuration entity to populate under autocomplete list.
We have setup a custom entity named Configuration, where we have not created any custom fields so we are just using default primary attribute field to store possible options for salutations.

Using this custom entity CRM admin can create/delete required salutations easily, so it is easy to configure list options without any coding changes. We will write OData query to get list of our configuration entity records and will utilize here retrievemultiple method of CRM organization service to get data based on the character enter by the user, so our query filter will be like the following,
- var odataQuery = "?$select=him_name&$top=10&" +
- "$filter=startswith(him_name,'" + salutationtxt + "')";
Note: Here we are using schema name of the attributes, because in OData query we need to use schema name of the entity and attributes. You can get schema name of the entity and attributes from solution.
In above query we are just retrieving name attribute and applied top clause to fetch only 10 records, in case there are many record based on the character entered by the user. To filter results we are using startswith operator which will compare first character of this attribute value.
To write OData query we will use SDK.Rest.js library that comes with SDK, so we need add this library as a web resource in CRM, please refer our earlier article for how to do the same.
We need to update our earlier AutoCompleteSalutations.js web resource with the following code (if you have not check our earlier article, please read it here first):



Elangamban MPosted Jun 4, 2016, 1:03 PM
How to trigger this autocomplete from a textbox which is inside HTML Webresource? Thanks