Share Entity record with Team


          Below is the sample code to share entity record with team in MS CRM 2011

            var teamReference = new EntityReference(“team”, teamId);
            var grantAccessRequest = new GrantAccessRequest
            {
                PrincipalAccess = new PrincipalAccess
                {
                    AccessMask=AccessRights.ReadAccess | AccessRights.WriteAccess,        
                    Principal=teamReference
                },

                Target=new EntityReference(“lead”,recordId)

            };
            service.Execute(grantAccessRequest);

           // Get teamId from below function

private Guid GetTeamId(string teamName,OrganizationService service)
        {
            Guid teamId=Guid.Empty;
            QueryByAttribute query = new QueryByAttribute();
            ColumnSet cols = new ColumnSet();
            cols.AddColumn(“teamid”); 

            query.ColumnSet = cols;
            query.AddAttributeValue(“name”, teamName);
            query.EntityName = “team”; 

            EntityCollection entityCollection = (EntityCollection)service.RetrieveMultiple(query);              
            if (entityCollection.Entities.Count > 0)
            {
                    Entity entity =entityCollection.Entities[0];
                    teamId = entity.Id;
            }
            return teamId;          

        }

I have already posted the same for CRM 4.0. Please find the reference link below.
https://arvindcsit.wordpress.com/2012/02/26/create-contact-and-share-the-record-which-contains-lookuppicklist-and-string-datatype/

 

Populate OptionSet value from MS CRM 2011 into DropDownList in ASP.NET


We had a requirement to create CRM record from custom ASP.NET page. There was an OptionSet on CRM Form which we need to display the option value in DropDownList of ASP.NET page. Below is the sample code to populate OptionSet value into DropDownList.

// Create Dictionary object to store the OptonSet value.
Dictionary<int, string> dropDownSource = new Dictionary<int, string>();

// Create Retrieve reuest
RetrieveAttributeRequest optionSetRequest = new RetrieveAttributeRequest();
optionSetRequest.EntityLogicalName = “lead”;
optionSetRequest.LogicalName = “leadqualitycode”;
optionSetRequest.RetrieveAsIfPublished = true;

RetrieveAttributeResponse optionSetResponse = (RetrieveAttributeResponse)service.Execute(optionSetRequest);

// Access retrive metadata

PicklistAttributeMetadata retrieveOptionSetMetadata = (PicklistAttributeMetadata)optionSetResponse.AttributeMetadata;

//get current optionlist for attribute

OptionMetadata[] optionList = retrieveOptionSetMetadata.OptionSet.Options.ToArray();

foreach (OptionMetadata o in optionList)
{
dropDownSource.Add(int.Parse(o.Value.ToString()), o.Label.UserLocalizedLabel.Label.ToString());
}

// ddlRating is object of dropdownlist
ddlRating.DataSource = dropDownSource;
ddlRating.DataBind();