Im am trying to retrieve the systemusers parentbusinessunit id or name i c#
This is how i do it, but there must be a better,smarter way to do it:
Guid userid = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).UserId;
WhoAmIRequest who = new WhoAmIRequest();
WhoAmIResponse whoResp = (WhoAmIResponse)_service.Execute(who);
Guid currentUserId = whoResp.UserId;
string ownerid = currentUserId.ToString();
ColumnSet allFields = new ColumnSet() { AllColumns = true };
Entity user = _service.Retrieve("systemuser", currentUserId, allFields);
Guid businessUnitId = ((EntityReference)user.Attributes["businessunitid"]).Id;
Entity businessunit = _service.Retrieve("businessunit", businessUnitId, allFields);
Guid parentBusinessUnitId = ((EntityReference)businessunit.Attributes["parentbusinessunitid"]).Id;
Entity parentBU = _service.Retrieve("businessunit", parentBusinessUnitId, allFields);
Appreciate all the help!
thanks in advanced.