{"id":2155,"date":"2016-03-24T07:59:05","date_gmt":"2016-03-24T07:59:05","guid":{"rendered":"http:\/\/himbap.com\/blog\/?p=2155"},"modified":"2016-03-24T08:39:21","modified_gmt":"2016-03-24T08:39:21","slug":"using-web-api-function-in-crm-2016-part-2","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=2155","title":{"rendered":"Using Web API Function in CRM 2016 Part 2"},"content":{"rendered":"<p>In our <a href=\"https:\/\/himbap.com\/blog\/?p=2134\">last article<\/a> we discussed about standard functions, today we are going to discuss Query Function. These functions are basically conditional operators, so there is conditional operator corresponding to every query function. we can get complete list of query function reference from <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt607843.aspx\">here<\/a>. We can use these functions similar to standard function, but we just need to make sure to include full name of the function while using it. <\/p>\n<p>Following is the sample code for using query function:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction GetNextMonthEvents() {\r\n    var serverURL = Xrm.Page.context.getClientUrl();\r\n    var req = new XMLHttpRequest();\r\n    req.open(&quot;GET&quot;, serverURL + &quot;\/api\/data\/v8.0\/him_events?$select=him_eventname&amp;$filter=Microsoft.Dynamics.CRM.NextMonth(PropertyName='him_eventstartdate')&quot;, true);\r\n    req.setRequestHeader(&quot;Accept&quot;, &quot;application\/json&quot;);\r\n    req.setRequestHeader(&quot;Content-Type&quot;, &quot;application\/json; charset=utf-8&quot;);\r\n    req.setRequestHeader(&quot;OData-MaxVersion&quot;, &quot;4.0&quot;);\r\n    req.setRequestHeader(&quot;OData-Version&quot;, &quot;4.0&quot;);\r\n    req.onreadystatechange = function() {\r\n        if (this.readyState == 4 \/* complete *\/ ) {\r\n            req.onreadystatechange = null;\r\n            if (this.status == 200) {\r\n                var data = JSON.parse(this.response);\r\n                alert(data.value.length);\r\n            } else {\r\n                var error = JSON.parse(this.response).error;\r\n                alert(error.message);\r\n            }\r\n        }\r\n    };\r\n    req.send();\r\n}\r\n\r\n<\/pre>\n<p>In above sample code we are using <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/mt607857.aspx\">NextMonth<\/a> query function. This query function takes one parameter, which is name of the attribute that we want to validate. We are using this function to get list of event that is happening next month. So it will query our custom event entity and will display number of event which is scheduled next month.<\/p>\n<p>Stay tuned for more Dynamics CRM updates!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our last article we discussed about standard functions, today we are going to discuss Query Function. These functions are basically conditional operators, so there is conditional operator corresponding to every query function. we can get complete list of query function reference from here. We can use these functions similar to standard function, but we just need to make sure&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=2155\">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":[275,296],"tags":[333,336,335,337],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2155"}],"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=2155"}],"version-history":[{"count":8,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2155\/revisions"}],"predecessor-version":[{"id":2164,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2155\/revisions\/2164"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}