{"id":129,"date":"2010-03-19T11:33:51","date_gmt":"2010-03-19T11:33:51","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=129"},"modified":"2010-03-19T11:33:51","modified_gmt":"2010-03-19T11:33:51","slug":"update-entity-record-using-dynamic-entity","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=129","title":{"rendered":"Update Entity Record Using Dynamic Entity"},"content":{"rendered":"<p><strong>I want to share somecode to update entity using dynamic entity with all<\/strong><\/p>\n<p>\/\/Create ICrmService object<\/p>\n<p>ICrmService\u00a0 _iCrmserviceObject=context.CreateCrmService(true);<\/p>\n<p>\/\/Create Dynamic entity object<\/p>\n<p>\u00a0DynamicEntity _DynamicEntity = new DynamicEntity();<\/p>\n<p>\/\/Assign name of entity which you want to update let\u2019s say account<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _DynamicEntity.Name = &#8220;account&#8221;;<\/p>\n<p>\/\/We have to add properties to dyanic entity that we want to update<\/p>\n<p>\/\/we can add directly to dynamic entity or can first create property and then add that property to dynamic entity<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Create a KeyProperty to hold the guid of the record to be updated<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _DynamicEntity.Properties.Add(new KeyProperty(&#8220;accountid&#8221;, new Key(GUID of record which you want to update)));<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _DynamicEntity.Properties.Add(new PicklistProperty(&#8220;accountcategorycode&#8221;, new Picklist(IntValue)));<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Create the update target.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0TargetUpdateDynamic _UpdateDynamic = new TargetUpdateDynamic();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ Set the properties of the target.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _UpdateDynamic.Entity = _DynamicEntity;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/\u00a0\u00a0 Create the update request object.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UpdateRequest _UpdateReq = new UpdateRequest();<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Set request properties.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _UpdateReq.Target = _UpdateDynamic;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/Execute the request.<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 UpdateResponse updated = (UpdateResponse)_iCrmserviceObject.Execute(_UpdateReq);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I want to share somecode to update entity using dynamic entity with all \/\/Create ICrmService object ICrmService\u00a0 _iCrmserviceObject=context.CreateCrmService(true); \/\/Create Dynamic entity object \u00a0DynamicEntity _DynamicEntity = new DynamicEntity(); \/\/Assign name of entity which you want to update let\u2019s say account \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 _DynamicEntity.Name = &#8220;account&#8221;; \/\/We have to add properties to dyanic entity that we want to update \/\/we can add directly&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=129\">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":[22],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/129"}],"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=129"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/129\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}