Hi All,
JavaScript to get
Business Unit ID For the User
var businessUnitId = GetBusinessUnitIDFortheUser
(loggedInUser);
function GetBusinessUnitIDFortheUser(userId) {
try {
if (serverUrl == null) {
serverUrl = GetCRMServerUrl();
}
var oDataEndpointUrl = Xrm.Page.context.getServerUrl()
+ "/XRMServices/2011/OrganizationData.svc/";
oDataEndpointUrl += "SystemUserSet?$select=BusinessUnitId&$filter=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 == 1) {
var userRecord = requestResults.results[0];
if (userRecord.BusinessUnitId && userRecord.BusinessUnitId.Id) {
return
userRecord.BusinessUnitId.Id;
}
}
}
return "";
}
catch (err) {
return "";
}
}
I think that thanks for the valuabe information and insights you have so provided here. dig this
ReplyDelete