Archive

Posts Tagged ‘user part of team’

Checking whether user part of team using jscript CRM 2011

June 23, 2012 2 comments

Hi,

We can verify whether the User is part of particular Team using jscript.

Below is the jscript function

function isUserPartOfTeam(userId, teamId) {

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

oDataEndpointUrl += “TeamMembershipSet?$select=BusinessUnitId&$filter=TeamId eq guid'” + teamId + “‘ SystemUserId eq guid'” + userId + “‘”;

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 true;

}

}

return false;

}

How do I call this method :-

  • Pass User Id & Team Id to the function.
  • Function returns true/false

var userId={User GUID};

var teamId={Team GUID};

var flag= isUserPartOfTeam(userId, teamId);

🙂