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,
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):
Now we need to add our SDK script web resource to contact entity form and need to call ContactOnLoad method on contact form OnLoad like the following, Make sure to keep SDK.Rest.js first in order. Save and publish your changes and now try to modify salutation field for existing or new contact record, it will load list from configuration entity like the following,
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: