This article compares the differences between the two query strings in the same OData query method, and also describes how to compare the values of the GUIDs returned by different methods.
With the same OData query method, if the string of the incoming query is different, the format of the returned result is completely different.
1. OData Query method:
OData Query
odataretrieve:function (odatastring) { var retrievereq = new XMLHttpRequest (); Retrievereq.open ("GET", encodeURI (XRM.PAGE.CONTEXT.GETCLIENTURL () + "/xrmservices/2011/ organizationdata.svc/" + odatastring), false); Retrievereq.setrequestheader ("Accept", "Application/json"); Retrievereq.setrequestheader ("Content-type", "Application/json;charset=utf-8"); retrievereq.send (); return json.parse (retrievereq.responsetext). D; }
2. The first method of querying
The query parameters are as follows:
var buvalue = Xrm.Page.getAttribute (' Tm_businessunit '). GetValue () [0].id; var odatastring = ' Businessunitset? $select =tm_systemuser_businessunit_nltautosales/parentsystemuserid & $expand =tm_systemuser_businessunit_nltautosales& $filter =businessunitid eq guid\ ' + buvalue + ' \ ";
The filter is used here.
You can see the results returned in the following format:
We must use Retrievedopp. Results[0]. Tm_systemuser_businessunit_nltautosales. Parentsystemuserid to get results
3. Second method of querying
The query parameters are as follows:
var buvalue = Xrm.Page.getAttribute (' Tm_businessunit '). GetValue () [0].id; var odatastring = ' Businessunitset (guid\ ' + buvalue + ' \ ')? $select =tm_systemuser_businessunit_ nltautosales/parentsystemuserid& $expand =tm_systemuser_businessunit_nltautosales ';
There is no use of the filter, the GUID used directly.
The results returned are as follows:
We can use retrievedopp.tm_systemuser_businessunit_nltautosales. Parentsystemuserid to get results
4. Guid comparison
If GUIDs are GUIDs that are taken from the interface using the same method, such as GetValue (), we can compare their values directly with [0].id], if the GUID returned by OData is compared with the GUID of GetValue () on the interface. You will find that the GUID value returned with the above OData query method is not {}, and is lowercase, whereas the GUID used with GetValue () on the interface is not only used for {}, but also uppercase. At this time if directly with = = To compare, certainly is not. A general comparison method is described below.
Determine that two GUIDs are the same
Guidsisequal:function (GUID1, Guid2) {
false;
if NULL null) {
"" ""). toLowerCase ();
}
return isequal;
}
Dynamic CRM 2015 Learning Notes series Rollup
Dynamic CRM 2013 Learning Notes Series summary (46 articles)
Dynamic CRM 2015 Learning Note (3) OData Query method and GUID value comparison