{"id":23873,"date":"2020-06-16T13:48:34","date_gmt":"2020-06-16T13:48:34","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=23873"},"modified":"2021-08-25T11:15:38","modified_gmt":"2021-08-25T11:15:38","slug":"how-to-get-users-security-role-name-using-client-api-in-dynamics-365-crm","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/06\/how-to-get-users-security-role-name-using-client-api-in-dynamics-365-crm\/","title":{"rendered":"How to get user\u2019s security role name using client API in Dynamics 365 CRM"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p style=\"text-align: justify;\">While doing any development with Dynamics 365 CRM, there might be a requirement of handling a few things like form attributes based on the security role. In many projects or applications of Dynamics 365 CRM where developers have to handle a few fields or tabs of CRM by showing\/hiding the same to Dynamics 365 users based on their security role. To do so, developer retrieves the security role of logged-in user and checks for the specific security role to show\/hide fields or any other controls of CRM.<\/p>\n<p>Now, to retrieve the user\u2019s security role we were using Microsoft client API as below:<\/p>\n<p><strong>var userSettings = Xrm.Utility.getGlobalContext().userSettings<\/strong><\/p>\n<p>Using above API we get the logged-in user\u2019s details like User Id, Date format, Security roles, etc.<\/p>\n<p>Further, to get the security roles we used <strong>userSettings.securityRoles<\/strong><\/p>\n<p style=\"text-align: justify;\">So, using this we get the list of all role Id of security roles assigned to the logged-in user. However, we could not get the security role names. So, we need to write another code to retrieve all the security roles from CRM and then, we need to write the logic to get the security role name by using the role Id.<\/p>\n<p style=\"text-align: justify;\">However, now we do not have to write extra code to get security role name based on the role Id which was assigned to user. In the spring release of 2020, Microsoft has provided alternate API to the deprecation of <strong>userSettings.securityRoles<\/strong>. Microsoft has replaced this API with \u00a0<strong>Xrm.Utility.getGlobalContext().userSettings.roles<\/strong>.<\/p>\n<p>So, using the updated API we get\u00a0 logged-in user\u2019s security roles with its role Id in the _collection as shown in the screenshot below:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-23874\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/client-API-in-Dynamics-365-CRM.png\" alt=\"client API in Dynamics 365 CRM\" width=\"687\" height=\"319\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/client-API-in-Dynamics-365-CRM.png 610w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/06\/client-API-in-Dynamics-365-CRM-300x139.png 300w\" sizes=\"(max-width: 687px) 100vw, 687px\" \/><\/p>\n<p style=\"text-align: justify;\">Now, it became easier for developers to get the current user\u2019s security role name and achieve the functionality like show\/hide or enable\/disable any form attributes programmatically as per requirement. It will save time and line of code of developer as we will get the desired result i.e. role names with this updated Client API.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Using the updated client API, we will get the user\u2019s security role name easily without writing any extra code.<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">Free 70% of storage space in CRM with Attachment Management Apps!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/attach-2-dynamics-365-crm-upload-multiple-files-sharepoint-cloud-storage\" target=\"_blank\" rel=\"noopener noreferrer\">Attach2Dynamics<\/a> &#8211; Store and manage documents\/attachments in cloud storage of your choice &#8211; SharePoint, Dropbox or Azure Blob Storage from within Dynamics 365 CRM.<\/em><br \/>\n<em><strong><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/dynamics-365-crm-sharepoint-security-metadata-sync\" target=\"_blank\" rel=\"noopener noreferrer\">SharePoint Security Sync<\/a><\/strong> \u2013 Robust and secure solution to integrate Dynamics 365 CRM and SharePoint Security Sync thereby ensuring secure access to confidential documents stored in SharePoint.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction While doing any development with Dynamics 365 CRM, there might be a requirement of handling a few things like form attributes based on the security role. In many projects or applications of Dynamics 365 CRM where developers have to handle a few fields or tabs of CRM by showing\/hiding the same to Dynamics 365\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/06\/how-to-get-users-security-role-name-using-client-api-in-dynamics-365-crm\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":23876,"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":[1],"tags":[2046],"class_list":["post-23873","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-client-api-in-dynamics-365-crm"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/23873","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=23873"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/23873\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/23876"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=23873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=23873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=23873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}