{"id":2355,"date":"2024-10-08T08:54:28","date_gmt":"2024-10-08T08:54:28","guid":{"rendered":"https:\/\/vm-automatisierung.com\/?p=2355"},"modified":"2024-10-08T08:54:28","modified_gmt":"2024-10-08T08:54:28","slug":"how-to-multiselect-from-combobox-and-relate-it-to-sql-table-in-powerapps","status":"publish","type":"post","link":"https:\/\/vm-automatisierung.com\/?p=2355","title":{"rendered":"How to multiselect from Combobox and relate it to SQL Table in Powerapps"},"content":{"rendered":"\n<p class=\"has-large-font-size\">My specific Task at hand: <\/p>\n\n\n\n<p>The objective is to develop a PowerApp that enables users to select specific groups within the organizational structure and retrieve the corresponding email addresses of all individuals stored in the Active Directory for the selected group. This solution will streamline the process of accessing and managing contact information within internal directory system.<\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Prerequisites<\/summary>\n<ul class=\"wp-block-list\">\n<li>Gateway with connection to the SQL Database established<\/li>\n\n\n\n<li>Sharepoint List to store and afterwards use the information gained<\/li>\n<\/ul>\n<\/details>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\" style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)\"><strong>Create a Powerapp from the SharePoint-List you want to save into<\/strong><\/p>\n\n\n\n<p>Fill it with the columns you wish to fill<\/p>\n\n\n\n<p>Allow multiselect for the column that you want to select the input out of<br>Create at least two more columns for active directory and e-mails<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\" style=\"margin-top:var(--wp--preset--spacing--30);margin-bottom:var(--wp--preset--spacing--30)\"><strong>Connect Combobox with onprem Dataset<\/strong><\/p>\n\n\n\n<p>Data &#8211;> Add data &#8211;> SQL Server<br><br><em>You will need verify this connection (I used windows credentials of a ServiceUser with permissions to access the DB)<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"330\" height=\"613\" src=\"https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2024\/10\/image-1.png\" alt=\"\" class=\"wp-image-2357\" srcset=\"https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2024\/10\/image-1.png 330w, https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2024\/10\/image-1-162x300.png 162w\" sizes=\"(max-width: 330px) 100vw, 330px\" \/><\/figure>\n\n\n\n<p><strong>Select a Combobox<\/strong> from the Card you want to multiselect out of &#8220;Unlock to Change Properties&#8221; and under<strong> Item<\/strong> establish your SQL Connection<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"774\" height=\"153\" src=\"https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2024\/10\/image-3.png\" alt=\"\" class=\"wp-image-2359\" srcset=\"https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2024\/10\/image-3.png 774w, https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2024\/10\/image-3-300x59.png 300w, https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2024\/10\/image-3-768x152.png 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Show and Save active directory and Mail-list<\/strong><\/p>\n\n\n\n<p>Create two more Cards &#8211;> one to show and save the active directory and one to show and save the mail-list<\/p>\n\n\n\n<p><strong>here is the tricky part:<\/strong><br>since we want every single one of the possibly selections from the group field to give us one or more active directory with inturn gives us one or more mail-addresses<br><br>we have two <strong>n:m connections<\/strong> which is something that requires many workarounds in powerapps , which is the reason for my blogpost.<br><br>For datasets with fewer than 500 entries, the &#8220;in&#8221; operator can be utilized effectively. However, since our dataset is growing and already exceeds 500 entries, we need to implement a non-delegable solution. Additionally, it is best practice to avoid relying on such fragile methods to ensure scalability and robustness in handling larger datasets.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Solution<\/strong><\/p>\n\n\n\n<p>We want to use an <strong>ForAll <\/strong>function to iterate through the the SelctedItems of the DataCard.<br><br>This poses the problem that ForAll doesn&#8217;t allow tables to be returned for each of the entries (it&#8217;s a n:1 connection). <br>To make it n:m we need to use a workaround again:<br><br>Nest the <strong>Filter <\/strong>function which returns the AD or Mail Value for each Group selected in a <strong>Concat<\/strong> function. &#8211;> this returns a string of all the outputs and can be used in ForAll.<br><br>To get the <strong>final table<\/strong> we Concat everything and then use the <strong>Split <\/strong>function over the entire Code. I also used the Distinct function to ensure every entry is only represented one time.<br><br>In my case the result looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Distinct<\/mark>(\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Split<\/mark>(<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Concat<\/mark>(\n        <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">ForAll<\/mark>(\n            <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Split<\/mark>(\n                <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Concat<\/mark>(\n                    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#8c0686\" class=\"has-inline-color\">DataCardValue2<\/mark>.SelectedItems,\n                    Value,\n                    <mark style=\"background-color:rgba(0, 0, 0, 0);color:#c41111\" class=\"has-inline-color\">\",\"<\/mark>\n                ),\n                <mark style=\"background-color:rgba(0, 0, 0, 0);color:#c41111\" class=\"has-inline-color\">\",\"<\/mark>\n            ),\n            <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Concat<\/mark>(\n                <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Distinct<\/mark>(\n                    <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-ast-global-color-0-color\">Filter<\/mark>(\n                        <mark style=\"background-color:rgba(0, 0, 0, 0);color:#23b990\" class=\"has-inline-color\">VM-Automatisierung_Groups<\/mark>,\n                        Service = Value\n                    ),\n                    AD_Gruppe\n                ),\n                Value,\n                <mark style=\"background-color:rgba(0, 0, 0, 0);color:#c41111\" class=\"has-inline-color\">\",\"<\/mark>\n            )\n        ),\n        Value,\n        <mark style=\"background-color:rgba(0, 0, 0, 0);color:#c41111\" class=\"has-inline-color\">\",\"<\/mark>),<mark style=\"background-color:rgba(0, 0, 0, 0);color:#c41111\" class=\"has-inline-color\">\",\"<\/mark>\n),Value)<\/code><\/pre>\n\n\n\n<div class=\"wp-block-group is-content-justification-center is-nowrap is-layout-flex wp-container-core-group-is-layout-23441af8 wp-block-group-is-layout-flex\"><div class=\"is-default-size wp-block-site-logo\"><a href=\"https:\/\/vm-automatisierung.com\/\" class=\"custom-logo-link\" rel=\"home\"><img decoding=\"async\" width=\"286\" height=\"338\" src=\"https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2023\/12\/Logo-ohne-hintergrundbild-2-83x98.png\" class=\"custom-logo\" alt=\"Logo-w\/oBack\" srcset=\"https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2023\/12\/Logo-ohne-hintergrundbild-2.png 286w, https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2023\/12\/Logo-ohne-hintergrundbild-2-254x300.png 254w, https:\/\/vm-automatisierung.com\/wp-content\/uploads\/2023\/12\/Logo-ohne-hintergrundbild-2-83x98.png 83w\" sizes=\"(max-width: 286px) 100vw, 286px\" \/><\/a><\/div>\n\n\n<figure class=\"wp-block-pullquote\"><blockquote><p>Freedom through automation<\/p><cite>-Vito Millauer<\/cite><\/blockquote><\/figure>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>My specific Task at hand: The objective is to develop a PowerApp that enables users to select specific groups within the organizational structure and retrieve the corresponding email addresses of all individuals stored in the Active Directory for the selected group. This solution will streamline the process of accessing and managing contact information within internal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2362,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8,11],"tags":[22,18,21,20,23,15,16,17],"class_list":["post-2355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-auto","category-m365-support","tag-active-directory-in-powerapps","tag-avoid-delegation-with-multiselect","tag-forall-powerapps","tag-multiselect-combobox-get-all-values-powerapps","tag-nm-connection-powerapps","tag-power-apps-in-alternitive","tag-power-apps-in-operator-alternative","tag-powerapps"],"_links":{"self":[{"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=\/wp\/v2\/posts\/2355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2355"}],"version-history":[{"count":2,"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=\/wp\/v2\/posts\/2355\/revisions"}],"predecessor-version":[{"id":2363,"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=\/wp\/v2\/posts\/2355\/revisions\/2363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=\/wp\/v2\/media\/2362"}],"wp:attachment":[{"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vm-automatisierung.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}