{"id":410,"date":"2010-12-31T16:03:18","date_gmt":"2010-12-31T16:03:18","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=410"},"modified":"2010-12-31T16:03:18","modified_gmt":"2010-12-31T16:03:18","slug":"get-max-value-using-javascript","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=410","title":{"rendered":"Get Max value using Javascript"},"content":{"rendered":"<p>\u00a0If you want to fetch Max value from CRM entity record using Javascript, you can use below code, remember to change entity and field name accordingly<\/p>\n<p>var authenticationHeader = GenerateAuthenticationHeader();<\/p>\n<p>\/\/ Prepare the SOAP message.<\/p>\n<p>var xml = &#8220;&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242;?&gt;&#8221;+<\/p>\n<p>&#8220;&lt;soap:Envelope xmlns:soap=&#8217;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/'&#8221;+<\/p>\n<p>&#8221; xmlns:xsi=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema-instance'&#8221;+<\/p>\n<p>&#8221; xmlns:xsd=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema&#8217;&gt;&#8221;+<\/p>\n<p>authenticationHeader+<\/p>\n<p>&#8220;&lt;soap:Body&gt;&#8221;+<\/p>\n<p>&#8220;&lt;RetrieveMultiple xmlns=&#8217;http:\/\/schemas.microsoft.com\/crm\/2007\/WebServices&#8217;&gt;&#8221;+<\/p>\n<p>&#8220;&lt;query xmlns:q1=&#8217;http:\/\/schemas.microsoft.com\/crm\/2006\/Query'&#8221;+<\/p>\n<p>&#8221; xsi:type=&#8217;q1:QueryExpression&#8217;&gt;&#8221;+<\/p>\n<p>&#8220;&lt;q1:EntityName&gt;EntityName&lt;\/q1:EntityName&gt;&#8221;+ \/\/change entity name<\/p>\n<p>&#8220;&lt;q1:ColumnSet xsi:type=&#8217;q1:ColumnSet&#8217;&gt;&#8221;+<\/p>\n<p>&#8220;&lt;q1:Attributes&gt;&#8221;+<\/p>\n<p>&#8220;&lt;q1:Attribute&gt;FieldName&lt;\/q1:Attribute&gt;&#8221;+ \/\/change field name<\/p>\n<p>&#8220;&lt;\/q1:Attributes&gt;&#8221;+<\/p>\n<p>&#8220;&lt;\/q1:ColumnSet&gt;&#8221;+<\/p>\n<p>&#8220;&lt;q1:Orders&gt;&#8221; +<\/p>\n<p>&#8220;&lt;q1:Order&gt;&#8221; +<\/p>\n<p>&#8220;&lt;q1:AttributeName&gt;FieldName&lt;\/q1:AttributeName&gt;&#8221; + \/\/change field name<\/p>\n<p>&#8220;&lt;q1:OrderType&gt;Descending&lt;\/q1:OrderType&gt;&#8221; +<\/p>\n<p>&#8220;&lt;\/q1:Order&gt;&#8221; +<\/p>\n<p>&#8220;&lt;\/q1:Orders&gt;&#8221; +<\/p>\n<p>&#8220;&lt;\/query&gt;&#8221;+<\/p>\n<p>&#8220;&lt;\/RetrieveMultiple&gt;&#8221;+<\/p>\n<p>&#8220;&lt;\/soap:Body&gt;&#8221;+<\/p>\n<p>&#8220;&lt;\/soap:Envelope&gt;&#8221;;<\/p>\n<p>\/\/ Prepare the xmlHttpObject and send the request.<\/p>\n<p>var xHReq = new ActiveXObject(&#8220;Msxml2.XMLHTTP&#8221;);<\/p>\n<p>xHReq.Open(&#8220;POST&#8221;, &#8220;\/mscrmservices\/2007\/CrmService.asmx&#8221;, false);<\/p>\n<p>xHReq.setRequestHeader(&#8220;SOAPAction&#8221;,&#8221;http:\/\/schemas.microsoft.com\/crm\/2007\/WebServices\/RetrieveMultiple&#8221;);<\/p>\n<p>xHReq.setRequestHeader(&#8220;Content-Type&#8221;, &#8220;text\/xml; charset=utf-8&#8221;);<\/p>\n<p>xHReq.setRequestHeader(&#8220;Content-Length&#8221;, xml.length);<\/p>\n<p>xHReq.send(xml);<\/p>\n<p>\/\/ Capture the result.<\/p>\n<p>var resultXml = xHReq.responseXML;<\/p>\n<p>\/\/ Check for errors.<\/p>\n<p>var errorCount = resultXml.selectNodes(&#8216;\/\/error&#8217;).length;<\/p>\n<p>if (errorCount != 0)<\/p>\n<p>{<\/p>\n<p>var msg = resultXml.selectSingleNode(&#8216;\/\/description&#8217;).nodeTypedValue;<\/p>\n<p>alert(msg);<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>var results = resultXml.getElementsByTagName(&#8216;BusinessEntity&#8217;);<\/p>\n<p>var msg = &#8220;&#8221;;<\/p>\n<p>if (results.length == 0)<\/p>\n<p>{<\/p>\n<p>alert(msg);<\/p>\n<p>return;<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>if(results[0].selectSingleNode(&#8216;.\/q1:FieldName&#8217;)!=null)<\/p>\n<p>{<\/p>\n<p>var MaxValue = results[0].selectSingleNode(&#8216;.\/q1:FieldName&#8217;).nodeTypedValue;\u00a0\u00a0 \/\/change name of the field to get Max value<\/p>\n<p>alert(MaxValue);<\/p>\n<p>}<\/p>\n<p>}}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0If you want to fetch Max value from CRM entity record using Javascript, you can use below code, remember to change entity and field name accordingly var authenticationHeader = GenerateAuthenticationHeader(); \/\/ Prepare the SOAP message. var xml = &#8220;&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;utf-8&#8242;?&gt;&#8221;+ &#8220;&lt;soap:Envelope xmlns:soap=&#8217;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/&#8217;&#8221;+ &#8221; xmlns:xsi=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8217;&#8221;+ &#8221; xmlns:xsd=&#8217;http:\/\/www.w3.org\/2001\/XMLSchema&#8217;&gt;&#8221;+ authenticationHeader+ &#8220;&lt;soap:Body&gt;&#8221;+ &#8220;&lt;RetrieveMultiple xmlns=&#8217;http:\/\/schemas.microsoft.com\/crm\/2007\/WebServices&#8217;&gt;&#8221;+ &#8220;&lt;query xmlns:q1=&#8217;http:\/\/schemas.microsoft.com\/crm\/2006\/Query&#8217;&#8221;+ &#8221; xsi:type=&#8217;q1:QueryExpression&#8217;&gt;&#8221;+ &#8220;&lt;q1:EntityName&gt;EntityName&lt;\/q1:EntityName&gt;&#8221;+ \/\/change entity name &#8220;&lt;q1:ColumnSet&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=410\">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":[24,25],"tags":[],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/410"}],"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=410"}],"version-history":[{"count":0,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/410\/revisions"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}