{"id":27225,"date":"2021-03-09T07:52:03","date_gmt":"2021-03-09T07:52:03","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=27225"},"modified":"2021-12-30T14:30:22","modified_gmt":"2021-12-30T09:00:22","slug":"check-whether-the-current-logged-in-dynamics-365-crm-user-has-necessary-security-privileges-for-a-specific-entity-in-pcf-control","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/03\/check-whether-the-current-logged-in-dynamics-365-crm-user-has-necessary-security-privileges-for-a-specific-entity-in-pcf-control\/","title":{"rendered":"Check whether the current logged in Dynamics 365 CRM user has necessary security privileges for a specific entity in PCF Control"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>In this blog, we will get the idea on how we can check if the current logged-in user has Read\/Write\/Update access to any specific entity or not.<\/p>\n<h2>Scenario<\/h2>\n<p>We have one Boolean type PCF control on the Account entity. Based on the Yes \/ No value of PCF control, we want to create a Contact entity record for the Current Account.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/1-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-1.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-27229 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/1-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-1.jpeg\" alt=\"current if the logged-in user has Read\/Write\/Update access to any specific entity or not\" width=\"979\" height=\"472\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/1-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-1.jpeg 979w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/1-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-1-300x145.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/1-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-1-768x370.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/1-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-1-660x318.jpeg 660w\" sizes=\"(max-width: 979px) 100vw, 979px\" \/><\/a><br \/>\nSo, when the user is trying to set \u2018Yes\u2019 to the \u2018Create Contact\u2019 field, we want to first check whether the current user has \u2018 to Create\u2019 permission of Contact entity record or not.<\/p>\n<h2>Solution<\/h2>\n<p>We will achieve this with the help of <strong>context.utils.hasEntityPrivilege<\/strong> function that is used to detect whether the current logged-in user has Read\/Write permission for a specific entity or not. In our case, we need to check if the active users have \u2018to Create\u2019 permission for the Contact entity record. Please find the below code that we have used to find out the same.<br \/>\ncontext.utils.hasEntityPrivilege(&#8220;contact&#8221;,1,3)<br \/>\nwhere,<br \/>\ncontact = Entity type name for which we have to find privilege details for the said entity.<br \/>\n1 = It indicates Entity privilege type such as Read, Write, etc. In the above scenario, we check for Create privilege so 1 is associated with \u2018Create\u2019. Please find some other Entity type names with their code:<br \/>\nNone = 0<br \/>\nCreate = 1<br \/>\nRead = 2<br \/>\nWrite = 3<br \/>\nDelete = 4<br \/>\nAssign =5<br \/>\nShare =6<br \/>\nAppend =7<br \/>\nAppendTo =8<br \/>\n3 = It indicates the entity privilege depth of the specified entity. It has the following values:<br \/>\nNone = -1<br \/>\nBasic = 0<br \/>\nLocal = 1<br \/>\nDeep = 2<br \/>\nGlobal = 3<br \/>\nSo, by calling this function, we found that the current logged in user has \u2018to Create\u2019 permission for Contact entity record as shown in the below screenshot:<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/2-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-27228 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/2-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1.jpeg\" alt=\"current if the logged-in user has Read\/Write\/Update access to any specific entity or not\" width=\"981\" height=\"508\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/2-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1.jpeg 981w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/2-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-300x155.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/2-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-768x398.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/2-if-the-logged-in-user-has-ReadWriteUpdate-access-to-any-specific-entity-or-not-1-660x342.jpeg 660w\" sizes=\"(max-width: 981px) 100vw, 981px\" \/><\/a><\/p>\n<p>As per the result given by context.utils.hasEntityPrivilege function, we take a decision to create a record contact entity record or not.<\/p>\n<h2>Conclusion<\/h2>\n<p>Using context.utils.hasEntityPrivilege, we can easily retrieve the current logged in user privilege details.<\/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 noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-27230 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/A4D.jpg\" alt=\"Dynamics 365 Email Alerts\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/A4D.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/A4D-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/A4D-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/03\/A4D-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this blog, we will get the idea on how we can check if the current logged-in user has Read\/Write\/Update access to any specific entity or not. Scenario We have one Boolean type PCF control on the Account entity. Based on the Yes \/ No value of PCF control, we want to create a\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/03\/check-whether-the-current-logged-in-dynamics-365-crm-user-has-necessary-security-privileges-for-a-specific-entity-in-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":[16,19,1929],"tags":[545,592,1941],"class_list":["post-27225","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-dynamics-crm","category-pcf","tag-dynamics-365-crm","tag-dynamics-crm","tag-pcf-control"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/27225","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=27225"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/27225\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=27225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=27225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=27225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}