{"id":39460,"date":"2024-10-11T12:43:52","date_gmt":"2024-10-11T07:13:52","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=39460"},"modified":"2024-10-11T12:43:52","modified_gmt":"2024-10-11T07:13:52","slug":"show-hide-buttons-based-on-entity-permissions-using-power-fx","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2024\/10\/show-hide-buttons-based-on-entity-permissions-using-power-fx\/","title":{"rendered":"Show\/Hide Buttons Based on Entity Permissions Using Power FX"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-39465\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX.png\" alt=\"Entity Permissions Using Power FX\" width=\"2800\" height=\"1600\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX.png 2800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-300x171.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-1024x585.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-768x439.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-1536x878.png 1536w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-2048x1170.png 2048w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-660x377.png 660w\" sizes=\"(max-width: 2800px) 100vw, 2800px\" \/><\/p>\n<p style=\"text-align: justify;\">Recently, we received a client requirement to show a button to users who have the <strong>Create <\/strong>permission for a specific entity. In the traditional approach, we would use the Ribbon Workbench in XrmToolBox to add buttons and write JavaScript code to check user permissions. While this method works fine, it can be a bit complex and technical.<\/p>\n<p style=\"text-align: justify;\">After doing some research and exploring Microsoft Docs, we found a <strong>Power Fx formula:<\/strong><\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\">DataSourceInfo({EntityName},DataSourceInfo.{Permission})<\/span><\/p>\n<p style=\"text-align: justify;\">This formula checks the Table (Entity) permission. By using the Power Fx formula, we can easily control the visibility of the button based on permissions. This method is much simpler.<\/p>\n<h2 style=\"text-align: justify;\"><strong>How to Implement This in Dynamics 365<\/strong><\/h2>\n<p><strong>1. Create a New Button<\/strong>: Using the <strong>Command Bar Editor<\/strong> in Dynamics 365, create a new button that we need to hide or show based on privileges.<\/p>\n<p style=\"text-align: justify; padding-left: 40px;\">For more detailed guidance, refer to <a href=\"https:\/\/www.inogic.com\/blog\/2021\/08\/new-command-bar-designer-using-powerfx-for-dataverse-and-dynamics-365-crm-apps-now-in-preview\/\" target=\"_blank\" rel=\"noopener\">the Customize the command bar using command designer.<\/a><\/p>\n<p><strong>2. Set Button Properties<\/strong>: In the properties of the newly created button, go to the <strong>Visibility<\/strong> section and select &#8220;<strong>Show on Condition from Formula<\/strong>.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-39461\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-1.png\" alt=\"Entity Permissions Using Power FX 1\" width=\"344\" height=\"196\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-1.png 344w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-1-300x171.png 300w\" sizes=\"(max-width: 344px) 100vw, 344px\" \/><\/p>\n<p><strong>3. Add the Formula:<\/strong> For example, if we want to show a button only if the user has <strong>Create <\/strong>permission for the <strong>Account<\/strong> entity, we use the <strong>DataSourceInfo<\/strong> function with Create Permissions in the Power FX formula.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-39462\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-2.png\" alt=\"Entity Permissions Using Power FX 1\" width=\"1242\" height=\"218\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-2.png 1242w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-2-300x53.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-2-1024x180.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-2-768x135.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-2-660x116.png 660w\" sizes=\"(max-width: 1242px) 100vw, 1242px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\">Fx Formula: If((DataSourceInfo(Accounts,DataSourceInfo.CreatePermission)), true, false)<\/span><\/p>\n<p style=\"text-align: justify;\">For more information about DataSourceInfo, you can check for other permissions such as:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-39463\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-3.png\" alt=\"Entity Permissions Using Power FX 1\" width=\"1208\" height=\"279\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-3.png 1208w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-3-300x69.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-3-1024x237.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-3-768x177.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-3-660x152.png 660w\" sizes=\"(max-width: 1208px) 100vw, 1208px\" \/><\/p>\n<p style=\"text-align: justify;\">Like DataSourceInfo, there is another method called <strong>RecordInfo<\/strong> that controls button visibility based on permissions related to individual records. While DataSourceInfo checks permissions at the entity wise, RecordInfo checks privileges for a specific record within that entity.<\/p>\n<p style=\"text-align: justify;\">For example, if you want to display a button only when the user has <strong>edit permissions<\/strong> on a selected record in Main Grid, use the following Power FX formula:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-39464\" style=\"border: 1px solid #000000; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-4.png\" alt=\"Entity Permissions Using Power FX 1\" width=\"1254\" height=\"219\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-4.png 1254w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-4-300x52.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-4-1024x179.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-4-768x134.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2024\/10\/Entity-Permissions-Using-Power-FX-4-660x115.png 660w\" sizes=\"(max-width: 1254px) 100vw, 1254px\" \/><\/p>\n<p style=\"text-align: justify;\"><span style=\"color: #ff0000;\">Fx Formula: If(RecordInfo(Self.Selected.Item, RecordInfo.EditPermission),true, false)<\/span><\/p>\n<h2 style=\"text-align: justify;\"><strong>Conclusion :<\/strong><\/h2>\n<p style=\"text-align: justify;\">The old approach of using the XrmToolBox Ribbon Workbench is functional but complex and time-consuming. To simplify this, we can use the Power FX DataSourceInfo function, which achieves the same result in less time and makes the process simpler.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/add-manage-schedule-notifications-alerts-4-dynamics-365-crm\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone wp-image-34569 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/04\/Alerts4Dynamics1-2.gif\" alt=\"Alerts4Dynamics\" width=\"800\" height=\"200\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, we received a client requirement to show a button to users who have the Create permission for a specific entity. In the traditional approach, we would use the Ribbon Workbench in XrmToolBox to add buttons and write JavaScript code to check user permissions. While this method works fine, it can be a bit complex\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2024\/10\/show-hide-buttons-based-on-entity-permissions-using-power-fx\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":11,"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":[16,2355],"tags":[2672],"class_list":["post-39460","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-powerfx","tag-power-fx"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/39460","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\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=39460"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/39460\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=39460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=39460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=39460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}