Sunday, 1 September 2013

Get the Bu Id plugin code



passing the org service and bu name :     

  private Guid getBuid(IOrganizationService crmServ)
        {
            #region get buId
            Guid recordId = new Guid();
            QueryExpression queryExp = new QueryExpression();
            queryExp.EntityName = BusinessUnit.EntityLogicalName;
            queryExp.ColumnSet = new ColumnSet();
            queryExp.ColumnSet.Columns.Add("businessunitid");
            ConditionExpression conExp = new ConditionExpression();
            conExp.AttributeName = "name";
            conExp.Operator = ConditionOperator.Equal;
            conExp.Values.Add("BU name");
            FilterExpression fep = new FilterExpression();
            fep.Conditions.Add(conExp);
            queryExp.Criteria.AddFilter(fep);

            EntityCollection entColl = crmServ.RetrieveMultiple(queryExp);

            {

                foreach (Entity user in entColl.Entities)
                {

                    recordId = (Guid)user["businessunitid"];

                }
            }
            return recordId;
            #endregion
        }

No comments:

Post a Comment