MS CRM 2011 Plugin 设置禁用启用状态
// 获取执行上下文
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
//创建SERVICE
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
_service = serviceFactory.CreateOrganizationService(context.UserId);
//InputParameters属性包含所有输入参数数据
if (context.InputParameters.Contains("EntityMoniker") && context.InputParameters["EntityMoniker"] is EntityReference)
{
EntityReference entityMoniker = context.InputParameters["EntityMoniker"] as EntityReference;
OptionSetValue state = context.InputParameters["State"] as OptionSetValue;
OptionSetValue status = context.InputParameters["Status"] as OptionSetValue;
//直接启用或者禁用单个数据是不需要写这玩意的,我这是更改这条数据的时候需要更改该数据的子数据的状态中用到的,贴的是部分代码。
SetStateRequest request = new SetStateRequest();
request.EntityMoniker = new EntityReference("crm_channel", entitys.Entities.ElementAt(i).Id);
request.State = new OptionSetValue(state.Value);
request.Status = new OptionSetValue(status.Value);
_service.Execute(request);
}