Featured Post

Dynamics 365 - Business Process Flow and Things to take note before you upgrade into Dynamics 365.

In 2 months ago, my company decided to upgrade the Dynamics CRM 2016 into Dynamics 365 and there is something different about Dynamics 365 B...

Wednesday, January 14, 2015

Dynamics CRM 2013 - OData Query

First, please go to https://crm2011odatatool.codeplex.com/ download the odata query designer solution and import into your CRM. Once you published the solution, go to Setting and look for Odata Query Designer.

1. Select the entity and the filter criteria based on your business requirements.













2. Click Generate




3. Now we going to create a web resources (JS),passing the value dynamically.

function Odata()
{
//Get Opportunity Id
var formType = Xrm.Page.ui.getFormType();
Master= Xrm.Page.getAttribute("crmfieldschemaname").getValue();

var guid = Master[0].id;
OdataCode(guid);

}

function OdataCode(guid)
{
  var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
  crmServerUrl = Xrm.Page.context.getServerUrl();
         var oDataUri =crmServerUrl+ODATA_ENDPOINT+"replace your code here";     jQuery.ajax({
       type: "GET",
       contentType: "application/json; charset=utf-8",
       datatype: "json",
       url: oDataUri,
       beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
       success: function (data, textStatus, XmlHttpRequest)
           {
               // Use only one of these two methods

               // Use for a selection that may return multiple entities

               ProcessReturnedEntities(data.d.results);
           },
       error: function (XmlHttpRequest, textStatus, errorThrown) {  alert("Ajax call failed: " + textStatus + " - " + errorThrown + " || " + XmlHttpRequest.responseText);}
   });
}

function ProcessReturnedEntities(ManyEntities)
{
  var grandTotal = 0;
  for(var i=0; i< ManyEntities.length; i++)
  {
     var oneEntity = ManyEntities[i];
     var totalPriceAttribute = oneEntity."the field that you want to select";                
}

}

4. thing to remember when you replace the filter value dynamically.


 var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
 crmServerUrl = Xrm.Page.context.getServerUrl();
       
var oDataUri =crmServerUrl+ODATA_ENDPOINT+"/new_petitionSet?$filter=new_CurrentMasterName/Id eq guid'"{remember to have a space here}+guid+"' and new_PetitionStatus/Id eq guid'50992E47-5518-E311-9CC8-005056A64D95'";  

No comments:

Post a Comment