{"id":2145,"date":"2015-12-12T14:21:58","date_gmt":"2015-12-12T08:51:58","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=2145"},"modified":"2026-02-03T11:04:46","modified_gmt":"2026-02-03T05:34:46","slug":"design-auto-complete-text-controls-in-dynamics-crm-2016","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2015\/12\/design-auto-complete-text-controls-in-dynamics-crm-2016\/","title":{"rendered":"Design Auto Complete Text controls in Dynamics CRM 2016"},"content":{"rendered":"<p><strong>Introduction:<\/strong><\/p>\n<p>On Dec 1<sup>st<\/sup> Microsoft released another great version of Dynamics CRM \u2013 CRM 2016 that has loads of new features and not to forget developer enhancements too.<\/p>\n<p>One of the developer enhancements added to Dynamics CRM 2016 is &#8220;<strong>Auto Complete<\/strong>&#8221; which allows us to provide auto complete feature for the single line text fields.<\/p>\n<p><strong>Configuring a control for Auto-Complete<\/strong><\/p>\n<p>Let us take an example to provide an auto complete list of cities for the City field on an entity.<\/p>\n<pre class=\"lang:default decode:true \">function listOfCities() {\r\n\r\n\u00a0\u00a0\u00a0 \/\/ List of sample cities names to suggest\r\n\r\n\u00a0\u00a0\u00a0 citites = [\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Toronto', country: 'Canada', code: '001',a:'0' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Aarhus', country: 'Denmark', code: '002' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Cairo', country: 'Egypt', code: '003' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Alexandria', country: 'Egypt', code: '004' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Bavaria', country: 'Germany', code: '005' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Baden-W\u00fcrttemberg', country: 'Germany', code: '006' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Mumbai', country: 'India', code: '007' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'New Delhi', country: 'India', code: '008' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Nashik', country: 'india', code: '009' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Hai Phong', country: 'Vietnam', code: '0010' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Ho Chi Minh', country: 'Vietnam', code: '0011' },\r\n\r\n\u00a0\u00a0\u00a0 { name: 'Mississauga', country: 'Canada', code: '0012' },\r\n\r\n\u00a0\u00a0\u00a0 ];\r\n\r\n\u00a0\u00a0\u00a0 var keyPressFcn = function (ext) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var userInput = Xrm.Page.getControl(\"address1_city\").getValue();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 resultSet = {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 results: new Array(),\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 commands: {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id: \"city\",\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 icon: \"..\/WebResources\/new_\/Images\/add.png\",\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/This will add the Link at the bottom of the auto complete search result\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 label: \"New\",\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 action: function () {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/specify the action that you want to perform on click of New Link\u00a0\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 window.open(\"https:\/\/crmtrial12.crm5.dynamics.com\");\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 };\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var userInputLowerCase = userInput.toLowerCase();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 for (i = 0; i &lt; citites.length; i++) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (userInputLowerCase === citites[i].name.substring(0, userInputLowerCase.length).toLowerCase()) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 resultSet.results.push({\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 id: i,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fields: [citites[i].name, citites[i].country, citites[i].code,],\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 icon: \"..\/WebResources\/new_\/Images\/add.png\"\r\n\r\n\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0});\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (resultSet.results.length &gt;= 10) break;\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (resultSet.results.length &gt; 0) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext.getEventSource().showAutoComplete(resultSet);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } else {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ext.getEventSource().hideAutoComplete();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 } catch (e) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 console.log(e);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n\u00a0\u00a0\u00a0 };\r\n\r\n\u00a0\u00a0\u00a0 Xrm.Page.getControl(\"address1_city\").addOnKeyPress(keyPressFcn);\r\n\r\n}<\/pre>\n<p>In the above source code, we have used three newly added functions in CRM 2016.<\/p>\n<ol>\n<li>showAutoComplete()<\/li>\n<li>hideAutoComplete()<\/li>\n<li>addOnKeyPress()<\/li>\n<\/ol>\n<ol>\n<li><strong>showAutoComplete()<\/strong><\/li>\n<\/ol>\n<p>This function is use to show the drop down list based on the string entered by the user in the text box. In our example, if you type \u201cA\u201d in the text box then it will display all the cities starting with \u201cA\u201d as shown below.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/12\/2016.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2146 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/12\/2016.png\" alt=\"Design Auto Complete Text controls\" width=\"630\" height=\"244\" \/><\/a><\/p>\n<ol start=\"2\">\n<li><strong>hideAutoComplete()<\/strong><\/li>\n<\/ol>\n<p>This function is use to hide the hide the drop down list. Or else you can simply click anywhere on the form then also this drop down list will get hide.<\/p>\n<ol start=\"3\">\n<li><strong>addOnKeyPress()<\/strong><\/li>\n<\/ol>\n<p>This function is called whenever we type any character in the text box.<\/p>\n<p>Xrm.Page.getControl(&#8220;address1_city&#8221;).addOnKeyPress(keyPressFcn);<\/p>\n<p>So to make this Auto complete functionality work, we need to call the function on the form load as shown below. In this example, we have called \u201c<strong>ListOfCities<\/strong>\u201d function on form load as shown below.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/12\/2016-1.png\"><img decoding=\"async\" class=\"aligncenter wp-image-2147 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/12\/2016-1.png\" alt=\"Design Auto Complete Text controls in crm 2016\" width=\"623\" height=\"571\" \/><\/a><\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>With auto-complete feature becoming a part of our daily use on the web, this now helps us provide a quick lookup to possible allowed values, without requiring the field to be converted into a Lookup.<\/p>\n<p>Just not this, before moving to the next post please visit\u00a0<a href=\"https:\/\/docs.maplytics.com\/\">Maplytics<\/a> InfoCentre &#8211; Bing Maps Integration for Microsoft Dynamics CRM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: On Dec 1st Microsoft released another great version of Dynamics CRM \u2013 CRM 2016 that has loads of new features and not to forget developer enhancements too. One of the developer enhancements added to Dynamics CRM 2016 is &#8220;Auto Complete&#8221; which allows us to provide auto complete feature for the single line text fields.\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2015\/12\/design-auto-complete-text-controls-in-dynamics-crm-2016\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[11,16,24,25,33],"tags":[181],"class_list":["post-2145","post","type-post","status-publish","format-standard","hentry","category-controls","category-dynamics-365","category-dynamics-crm-2016","category-dynamics-crm-2016-update-1","category-javascript","tag-auto-complete-text-controls"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=2145"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2145\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=2145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=2145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=2145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}