Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

How can i retrieve the systemusers parentbusinessunit name? in C#

$
0
0

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.


Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>