public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
//get initiating user (or impersonated user)
Guid userId = context.InitiatingUserId; //or context.UserId
//set up OrganizationService
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(userId);
//retrieve user record
ColumnSet allFields = new ColumnSet() { AllColumns = true };
Entity user = service.Retrieve("systemuser", userId, allFields);
//get business unit lookup
Guid businessUnitId = ((EntityReference)user.Attributes["businessunitid"]).Id;
//optional
Entity businessunit = service.Retrieve("businessunit", businessUnitId, allFields);
}
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
//get initiating user (or impersonated user)
Guid userId = context.InitiatingUserId; //or context.UserId
//set up OrganizationService
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(userId);
//retrieve user record
ColumnSet allFields = new ColumnSet() { AllColumns = true };
Entity user = service.Retrieve("systemuser", userId, allFields);
//get business unit lookup
Guid businessUnitId = ((EntityReference)user.Attributes["businessunitid"]).Id;
//optional
Entity businessunit = service.Retrieve("businessunit", businessUnitId, allFields);
}
Great Post!!
ReplyDeleteFor more : CRM Software || CRM Software in Mumbai