public string getBU(Guid userId)
{
string BU="";
var service = new OrganizationService(connection);
ColumnSet allFields = new ColumnSet() { AllColumns = true };
try
{
Entity team = service.Retrieve("team", userId, allFields);
Entity user = service.Retrieve("systemuser", userId, allFields);
Guid businessUnitId = ((EntityReference)user.Attributes["businessunitid"]).Id;
//optional
Entity businessunit = service.Retrieve("businessunit", businessUnitId, allFields);
BU = businessunit["name"].ToString();
}
catch (Exception)
{
;
}
return BU;
}