How to Get User Business Unit Name by [UserId] Microsoft Dynamics CRM

How to Get User Business Unit Name by [UserId] Microsoft Dynamics CRM

Get Business unit name

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

??????????????? Entity businessunit = service.Retrieve("businessunit", businessUnitId, allFields);

??????????????? BU = businessunit["name"].ToString();

??????????? }

??????????? catch (Exception)

??????????? {

?

????????? ????;

??????????? }

??????????? return BU;

?

???????? }

?)        

要查看或添加评论,请登录

Mohammed Salah的更多文章

社区洞察

其他会员也浏览了