{"id":3525,"date":"2018-12-22T09:15:45","date_gmt":"2018-12-22T09:15:45","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=3525"},"modified":"2018-12-22T09:15:45","modified_gmt":"2018-12-22T09:15:45","slug":"get-contact-based-on-name-and-its-bu-sample-code","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=3525","title":{"rendered":"Get contact based on name and it&#8217;s BU- Sample Code"},"content":{"rendered":"<p>If you got requirement to get contact record based on it&#8217;s full name and it&#8217;s business unit name, this sample code will help you. Sharing following sample code to get contact using Query Expression.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic Entity GetContactByFullNameandBUName(string contact,string businessunit)\r\n        {\r\n            Entity contactEntity = null;\r\n\r\n            \/\/ setup query expression to query contact for fullname and BU\r\n            var query = new QueryExpression(&quot;contact&quot;);\r\n            query.ColumnSet.AddColumns(&quot;fullname&quot;);\r\n            query.Criteria.AddCondition(&quot;fullname&quot;, ConditionOperator.Equal, contact);\r\n\t\t\t\r\n\t\t\t\/\/add link entity condition\r\n            var linkEntity = query.AddLink(&quot;businessunit&quot;, &quot;owningbusinessunit&quot;, &quot;businessunitid&quot;);\r\n            linkEntity.EntityAlias = &quot;BU&quot;;\r\n            linkEntity.Columns.AddColumns(&quot;businessunitid&quot;);\r\n            linkEntity.LinkCriteria.AddCondition(&quot;name&quot;, ConditionOperator.Equal, businessunit);\r\n\t\t\t\r\n\t\t\t\/\/execute query\r\n            EntityCollection results = organizationService.RetrieveMultiple(query);\r\n\r\n           if (results.Entities.Count&gt;0)\r\n            {\r\n                contactEntity = results.Entities.FirstOrDefault();\r\n\r\n            }\r\n            return contactEntity;\r\n        }\r\n<\/pre>\n<p>Hope it will help someone !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you got requirement to get contact record based on it&#8217;s full name and it&#8217;s business unit name, this sample code will help you. Sharing following sample code to get contact using Query Expression. Hope it will help someone !!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[402,522,8,275],"tags":[688,690,691,689],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3525"}],"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=3525"}],"version-history":[{"count":3,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3525\/revisions"}],"predecessor-version":[{"id":3528,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3525\/revisions\/3528"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}