{"id":304,"date":"2010-08-18T05:25:36","date_gmt":"2010-08-18T05:25:36","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=304"},"modified":"2010-08-18T05:25:36","modified_gmt":"2010-08-18T05:25:36","slug":"check-requirement-level-through-code","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=304","title":{"rendered":"Check Requirement Level through Code"},"content":{"rendered":"<p>Some time we need to check requirement level of specific attribute\u00a0in run time, this can be done using metadata webservice. For example I am taking accountnumber attribute of account entity, I have changed it\u2019s Requirement level to Business Required for my demo purpose so let\u2019s check through code, I have created a website project in Visual studio with default aspx form and a\u00a0command button on it, as metadata webservic reference to your website project. I have\u00a0written below code onclick of that button<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CRMMetadata.CrmAuthenticationToken token = new CRMMetadata.CrmAuthenticationToken();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 token.OrganizationName = &#8220;<strong>OrgName<\/strong>&#8220;; \/\/your organization name<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 token.AuthenticationType = 0;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Create the metadata Web service.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MetadataService metadataService = new MetadataService();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 metadataService.Url = &#8220;<strong>Metadatawebservice URL<\/strong>&#8220;; \/\/you need replace it with metadatawebservice url<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 metadataService.CrmAuthenticationTokenValue = token;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 metadataService.PreAuthenticate = true;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Create the request.<\/p>\n<p>\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 attributeRequest.EntityLogicalName = EntityName.account.ToString();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 attributeRequest.LogicalName = &#8220;<strong>accountnumber<\/strong>&#8220;; \/\/I want to check account number<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 attributeRequest.RetrieveAsIfPublished = false;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 RetrieveAttributeResponse attributeResponse = (RetrieveAttributeResponse)metadataService.Execute(attributeRequest);<\/p>\n<p>string RequirementLevel = attributeResponse.AttributeMetadata.RequiredLevel.Value.ToString();<\/p>\n<p>you will get\u00a0value of \u00a0<strong>RequirmentLevel<\/strong> as &#8220;Required&#8221; if it is set as \u201cBusiness Required\u201d\u00a0or if it is set to \u201cBusiness Recommended\u201d it will return you \u201cRecommended\u201d<\/p>\n<p>Hope it can help somebody !!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some time we need to check requirement level of specific attribute\u00a0in run time, this can be done using metadata webservice. For example I am taking accountnumber attribute of account entity, I have changed it\u2019s Requirement level to Business Required for my demo purpose so let\u2019s check through code, I have created a website project in Visual studio with default aspx&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=304\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/304"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=304"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/304\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}