When i tried to create another type of an entity record in the post update plugin stage I have gotten "Changing security attributes is not allowed in stage 20 plugins" error. Its working fine in Dynamics CRM 2013 SP1 CRM. After update CRM 2013 to CRM 2015 i got this error
3 Answers
2
votes
2
votes
2
votes
Some of you might get this error in the plugin steps when an organization is being migrated to CRM 2015. Cause:
- You change the ownership of the record in the record Pre-creation
Resolution:
- Most solutions out there say about change the plugin to Post-operation stage, but this don't make sense for some of the actions/checks that your plugin could do.
- So, what you could do is to check the pipeline stage before you run the assignment operation. https://msdn.microsoft.com/en-us/library/gg327941.aspx#bkmk_PipelineStages
Sample code:
//Runs on the Pre-Validation step, when a Contact is created
if (context.Stage == 10)
{
if (!targetEntity.Attributes.Contains("parentcustomerid"))
{
throw new InvalidPluginExecutionException("Message to show....");
}
try
{
var accountOwner = (from a in orgServiceContext.AccountSet
where a.Id == targetContact.ParentCustomerId.Id
select a).Single();
targetEntity.Attributes["ownerid"] = new EntityReference("team", accountOwner.OwnerId.Id);
targetEntity.Attributes["owningbusinessunit"] = new EntityReference("businessunit", accountOwner.OwningBusinessUnit.Id);
}
catch
{
throw new InvalidPluginExecutionException("Message to show...");
}
}
Found another solution: Move your plugin step to Pre-Validation.