{"id":29397,"date":"2021-09-24T16:24:53","date_gmt":"2021-09-24T10:54:53","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=29397"},"modified":"2021-10-07T10:50:06","modified_gmt":"2021-10-07T05:20:06","slug":"create-multi-select-optionset-using-pcf-control","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/09\/create-multi-select-optionset-using-pcf-control\/","title":{"rendered":"Create Multi Select Optionset using PCF Control"},"content":{"rendered":"<h2>Introduction:<\/h2>\n<p style=\"text-align: justify;\">Recently in one of our project, we had come acorss a requirement where we needed to create a PCF control for multi select optionset field \u00a0with which user can visualize the values in a list form.<\/p>\n<p style=\"text-align: justify;\">In the new updates of PowerApps Component Framework, with the help of MultiSelectOptionSet type property, now we can develop the PCF control for multi select optionset field. We have given an example, where we create a PCF control for multi select optionset field and added the same on custom multi select optionset field.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-29399 aligncenter\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/PCF-Control-ink.jpeg\" alt=\"PCF Control\" width=\"603\" height=\"368\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/PCF-Control-ink.jpeg 603w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/PCF-Control-ink-300x183.jpeg 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/p>\n<p>Given below are the steps to achieve the same:<\/p>\n<p><strong>1<\/strong>. First we need to add MultiSelectOptionSet property in ControlManifest.Input.xml file. The code is as follows:<\/p>\n<p>&lt;property\u00a0name=&#8221;sampleProperty&#8221;\u00a0display-name-key=&#8221;Property_Display_Key&#8221;\u00a0description-key=&#8221;Property_Desc_Key&#8221;\u00a0of-type=&#8221;MultiSelectOptionSet&#8221;\u00a0usage=&#8221;bound&#8221;\u00a0required=&#8221;true&#8221;\u00a0\/&gt;<\/p>\n<p><strong>2<\/strong>. Now define the IInput and IOutputs for multi select optionset in <strong>ManifestTypes.d.ts<\/strong> file.<\/p>\n<pre class=\"lang:css gutter:true start:1\">\/\/Define\u00a0IInputs\u00a0and\u00a0IOutputs\u00a0Type.\u00a0They\u00a0should\u00a0match\u00a0with\u00a0ControlManifest\r\nexport\u00a0interface\u00a0IInputs\u00a0{\r\nsampleProperty:\u00a0ComponentFramework.PropertyTypes.MultiSelectOptionSetProperty;\r\n}\r\nexport\u00a0interface\u00a0IOutputs\u00a0{\r\nsampleProperty?:\u00a0number[];\r\n}\r\n<\/pre>\n<p><strong>3<\/strong>. On load of multi select PCF control, set the current field value in multi select control inside init function.<\/p>\n<pre class=\"lang:css gutter:true start:1\">\/\/Create a select option for each option specified by the target OptionSet and add it to\u00a0the\u00a0dropdown\r\n(context.parameters.sampleProperty\u00a0as\u00a0ComponentFramework.PropertyTypes.MultiSelectOptionSetProperty).attributes?.Options.forEach(option\u00a0=&gt;\u00a0{\r\nconst dropdownOption = document.createElement(\"option\");\r\ndropdownOption.setAttribute(\"value\", String(option.Value));\r\ndropdownOption.innerText = option.Label;\r\ndropdownOption.onclick = this.updateIndividualSelected.bind(this, dropdownOption);\r\ndropdownOption.selected = this._selectedOptions.includes(option.Value);\r\nthis._dropdown.appendChild(dropdownOption);\r\n});\r\n<\/pre>\n<p><strong>4<\/strong>. Add the action on select of multi select optionset to select\/deselect the option.<\/p>\n<pre class=\"lang:css gutter:true start:1\">\/\/onClick\u00a0callback\u00a0for\u00a0individual\u00a0options\u00a0in\u00a0the\u00a0dropdown.\u00a0Clicking\u00a0an\u00a0option\u00a0will\u00a0add\/remove\u00a0it\r\nprivate\u00a0updateIndividualSelected(option:\u00a0HTMLOptionElement):\u00a0void\u00a0{\r\nconst value = Number(option.getAttribute(\"value\"))\r\nconst index = this._selectedOptions.indexOf(value);\r\nif (index === -1) {\r\nthis._selectedOptions.push(value);\r\noption.selected = true;\r\noption.className = \"TestBlue\";\r\n} else {\r\nthis._selectedOptions.splice(index, 1);\r\noption.selected = false;\r\noption.className = \"TestWhite\";\r\n}\r\nthis._notifyOutputChanged();\r\n}\r\n<\/pre>\n<p><strong>5<\/strong>. Set the changed value of multi select optionset using getOutputs function.<\/p>\n<pre class=\"lang:css gutter:true start:1\">\/\/It\u00a0is\u00a0called\u00a0by\u00a0the\u00a0framework\u00a0prior\u00a0to\u00a0a\u00a0control\u00a0receiving\u00a0new\u00a0data.\r\npublic\u00a0getOutputs():\u00a0IOutputs\r\n{\r\n\/\/Send the currently selected options back to the ComponentFramework\r\nreturn { sampleProperty: this._selectedOptions } ;\r\n}\r\n<\/pre>\n<h2>Conclusion:<\/h2>\n<p>In this way, with the help of new MultiSelectOptionSet type property, we can easily create the PCF control for the multi select optionset field.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/user-adoption-monitor-in-dynamics-crm\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone size-full wp-image-29404\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/User-Adoption-Monitor.jpg\" alt=\"User Adoption Monitor\" width=\"768\" height=\"192\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/User-Adoption-Monitor.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/User-Adoption-Monitor-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/09\/User-Adoption-Monitor-660x165.jpg 660w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Recently in one of our project, we had come acorss a requirement where we needed to create a PCF control for multi select optionset field \u00a0with which user can visualize the values in a list form. In the new updates of PowerApps Component Framework, with the help of MultiSelectOptionSet type property, now we can\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/09\/create-multi-select-optionset-using-pcf-control\/\">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":[1929,2361],"tags":[1941],"class_list":["post-29397","post","type-post","status-publish","format-standard","hentry","category-pcf","category-technical","tag-pcf-control"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/29397","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=29397"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/29397\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=29397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=29397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=29397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}