{"id":1271,"date":"2014-04-18T08:02:42","date_gmt":"2014-04-18T08:02:42","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=1271"},"modified":"2014-04-18T08:02:42","modified_gmt":"2014-04-18T08:02:42","slug":"update-sub-grids-record-in-ms-crm","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=1271","title":{"rendered":"Update sub grids record in MS CRM"},"content":{"rendered":"<p>Did you get a requirement to update child entity records available in sub grid in parent entity, so for example if you are working opportunity and you need to update all the related quotes records which is available in quote sub grids under opportunity screen. You can use below code and can modify based on your requirement<\/p>\n<p>function <strong>GetAllQuotesIds<\/strong>() {<br \/>\nvar gridControl = document.getElementById(&#8220;opportunityQuotesGrid&#8221;).control; \/\/Change grid name here<br \/>\nvar subGrid = gridControl.get_allRecordIds();<br \/>\nfor (i = 0; i &lt; subGrid.length; i++) {<br \/>\nvar Quote = new Object();<br \/>\nQuote.Name = &#8220;Demo&#8221;;\u00a0\u00a0 \u00a0\/\/ change to update your field<br \/>\nvar Id = subGrid[i].replace(&#8220;{&#8220;, &#8220;&#8221;).replace(&#8220;}&#8221;, &#8220;&#8221;);<br \/>\nUpdateQuotes(Id,Quote); } }<\/p>\n<p>function <strong>UpdateQuotes<\/strong>(Id,Quote)<br \/>\n{<br \/>\nvar jsonEntity = JSON.stringify(Quote);<br \/>\nvar ODataPath = Xrm.Page.context.getServerUrl() + &#8220;\/XrmServices\/2011\/OrganizationData.svc\/QuoteSet&#8221;; \/\/Change entity name here<br \/>\n$.ajax({ type: &#8220;POST&#8221;,<br \/>\ncontentType: &#8220;application\/json; charset=utf-8&#8221;,<br \/>\ndatatype: &#8220;json&#8221;,<br \/>\ndata: jsonEntity,<br \/>\nurl: ODataPath + &#8220;(guid'&#8221; + Id + &#8220;&#8216;)&#8221;,<br \/>\nbeforeSend: function (XMLHttpRequest)<br \/>\n{XMLHttpRequest.setRequestHeader(&#8220;Accept&#8221;, &#8220;application\/json&#8221;);<br \/>\nXMLHttpRequest.setRequestHeader(&#8220;X-HTTP-Method&#8221;, &#8220;MERGE&#8221;); },<br \/>\nsuccess: function (data, textStatus, XmlHttpRequest) { alert(&#8220;Success&#8221;); },<br \/>\nerror: function (XMLHttpRequest, textStatus, errorThrown) { alert(&#8220;Error while updating record&#8221; } }); }<\/p>\n<p>Make sure you have REST and Jquery libraries are added to your form.<\/p>\n<p>Hope it will help someone.<\/p>\n<p>Enjoy !!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Did you get a requirement to update child entity records available in sub grid in parent entity, so for example if you are working opportunity and you need to update all the related quotes records which is available in quote sub grids under opportunity screen. You can use below code and can modify based on your requirement function GetAllQuotesIds() {&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=1271\">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":[2,5,6],"tags":[161,197],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1271"}],"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=1271"}],"version-history":[{"count":1,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1271\/revisions"}],"predecessor-version":[{"id":2304,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1271\/revisions\/2304"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}