Check User is A Part of Team in MS CRM 2011 using ODATA JavaScript

Check User is A Part of Team in MS CRM 2011 using ODATA JavaScript

function team() {

var teamId = Xrm.Page.data.entity.attributes.get(“new_teamid”).getValue()[0].id;

var userId = Xrm.Page.context.getUserId();

if (teamId != null) {

var fwdFilter = “TeamMembershipSet?$filter=TeamId eq guid'”+teamId+”‘ and SystemUserId eq guid'”+userId+”‘”;

var fwdResult = ODataRetrieveMultiple(fwdFilter);

if (fwdResult != null)
{
alert(“User is part of This Team”);

}
else
{
alert(“User is not part of This Team”);
}

}

}
function ODataRetrieveMultiple(fwdFilter) {
var serverUrl = Xrm.Page.context.getServerUrl();

var oDataEndpointUrl = serverUrl + “/XRMServices/2011/OrganizationData.svc/”;

oDataEndpointUrl += fwdFilter;

var service = GetRequestObject();

if (service != null) {

service.open(“GET”, oDataEndpointUrl, false);

service.setRequestHeader(“X-Requested-Width”, “XMLHttpRequest”);

service.setRequestHeader(“Accept”, “application/json, text/javascript, */*”);

service.send(null);

var requestResults = eval(‘(‘ + service.responseText + ‘)’).d;

if (requestResults != null && requestResults.results.length > 0) {

return requestResults.results;

}

}

return null;

}

function GetRequestObject() {

if (window.XMLHttpRequest) {

return new window.XMLHttpRequest;

}

else {

try {

return new ActiveXObject(“MSXML2.XMLHTTP.3.0”);

}

catch (ex) {

return null;

}

}

}

 

Note: While you copy the code and paste in your form the punctuations are not recognized by JavaScript API . So need to replace the symbols like ” , ‘ * & for avoiding errors.

Cheers,

Hope This Code Help !!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s