Tuesday, 10 September 2013

MSCRM 2011 Plugin in user context to avail configured filed level security

var context = serviceProvider.GetService(typeof(IPluginExecutionContext)) as IPluginExecutionContext;
var target = new Entity("account");
target["name"] = "test 3";
target["new_secretcode"] = "1234";
var sf = serviceProvider.GetService(typeof(IOrganizationServiceFactory)) as IOrganizationServiceFactory;
var service = sf.CreateOrganizationService(Guid.Empty);
service.Create(target);

var service = sf.CreateOrganizationService(Guid.Empty);
To execute plugin in user context: The Create OrganizationService call that we pass Guid.Empty. Passing Guid.Empty instructs the method to give back an organization service configured to run in the context of the user


var service = sf.CreateOrganizationService(null);
To execute plugin in System context : we passed null to that method the organization service would be configured to run in the system context and the plugin would be able to update the secured field.


No comments:

Post a Comment