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

Issue while creating a Team using Dynamics CRM Plugins

$
0
0

Hi,

I am developing a plugin to create a team dynamically. I am getting some issue related to the business unit id.

Below are the code.

var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));


//Create the organization service
IOrganizationService service = factory.CreateOrganizationService(context.UserId);

ColumnSet allFields = new ColumnSet() { AllColumns = true };
Entity user = service.Retrieve("systemuser", context.UserId, allFields);

//get business unit lookup
Guid businessUnitId = ((EntityReference)user.Attributes["businessunitid"]).Id;


//create a team
Entity team = new Entity("team");
team["name"] = "Test Team";
team["businessunitid"] = businessUnitId;
team["administratorid"] = context.UserId;
                
// Create the team in Microsoft Dynamics CRM.
service.Create(team);

I am getting an error "Attribute: businessunitid cannot be set to NULL" on "service.Create(team)" line. I debug the code and found that I am getting Business Unit ID correctly.

Can anyone help me to fix this.

--

Thanks and Regards

Sandeep

CloudFronts Technologies

www.cloudfronts.com


Viewing all articles
Browse latest Browse all 82002

Trending Articles



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