var teamList = new Array();
try {
var query = "TeamMembershipSet?$select=TeamId,SystemUserId&$filter=SystemUserId eq guid'" + ConverttoStringFromGuid(userid) + "'";
var teamMemmberShipEntity = ODataRetrieveMultipleAjax(query);
if (teamMemmberShipEntity != null && teamMemmberShipEntity.results != null && teamMemmberShipEntity.results.length != 0) {
for (var i = 0; i < teamMemmberShipEntity.results.length; i++) {
if (teamMemmberShipEntity.results[i] != null) {
var _teamid = teamMemmberShipEntity.results[i].TeamId;
if (_teamid != null) {
var query2 = "TeamSet?$select=TeamId,Name&$filter=TeamId eq guid'" + ConverttoStringFromGuid(_teamid) + "'";
var teamEntity = ODataRetrieveMultipleAjax(query2);
if (teamEntity != null && teamEntity.results != null && teamEntity.results.length != 0) {
if (teamEntity.results.length == 1 && teamEntity.results[0] != null) {
teamList[teamList.length] = teamEntity.results[0].Name.toUpperCase();
}
}
}
}
}
}
}
catch (e) {
alert("An error occured in GetUserTeams Function.Message :" + e.message);
}
return teamList;
}
function ConverttoStringFromGuid(guidid) {
if (guidid != null && guidid != "") {
return guidid.toString().replace('{', '').replace('}', '').toUpperCase();
}
return "00000000-0000-0000-0000-000000000000";
}
function ODataRetrieveMultipleAjax(oDataSelect) {
var crmOrgSvc = Xrm.Page.context.prependOrgName("/xrmservices/2011/OrganizationData.svc/");
var result = null;
oDataSelect = crmOrgSvc + oDataSelect;
jQuery.support.cors = true;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataSelect,
async: false,
beforeSend: function (XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
if (data != null && data.d != null) {
result = data.d;
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown, "Error Function:" + "ODataRetrieveMultipleAjax");
}
});
return result;
}
Hiç yorum yok:
Yorum Gönder