Notifications
Announcements
No record found.
using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Query; using System; public class PreventAnnotationDeletion : IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); if (context.MessageName.ToLower() != "delete" || context.PrimaryEntityName.ToLower() != "annotation") return; Guid annotationId = context.PrimaryEntityId; Entity annotation = service.Retrieve("annotation", annotationId, new ColumnSet("ownerid", "createdby")); if (annotation != null) { EntityReference owner = annotation.GetAttributeValue<EntityReference>("ownerid"); EntityReference createdBy = annotation.GetAttributeValue<EntityReference>("createdby"); if (owner.Id != createdBy.Id) { throw new InvalidPluginExecutionException("Deletion is not allowed. The owner and the created by fields do not match."); } } } }
using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; using System; using System.Activities; public class CheckAnnotationCreator : CodeActivity { [Input("Annotation Created By")] [ReferenceTarget("systemuser")] public InArgument<EntityReference> AnnotationCreatedBy { get; set; } [Input("Annotation Object Id")] [ReferenceTarget("incident")] public InArgument<EntityReference> AnnotationObjectId { get; set; } [Output("Is Same User")] public OutArgument<bool> IsSameUser { get; set; } protected override void Execute(CodeActivityContext executionContext) { ITracingService tracingService = executionContext.GetExtension<ITracingService>(); IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>(); try { tracingService.Trace("CheckAnnotationCreator: Execute started."); EntityReference createdBy = AnnotationCreatedBy.Get(executionContext); EntityReference objectId = AnnotationObjectId.Get(executionContext); if (createdBy == null || objectId == null || objectId.LogicalName != "incident") { tracingService.Trace("CheckAnnotationCreator: Invalid input parameters."); IsSameUser.Set(executionContext, false); return; } tracingService.Trace($"CheckAnnotationCreator: Created By ID - {createdBy.Id}, User ID - {context.UserId}"); bool isSameUser = createdBy.Id == context.UserId; IsSameUser.Set(executionContext, isSameUser); tracingService.Trace($"CheckAnnotationCreator: Is Same User - {isSameUser}"); } catch (Exception ex) { tracingService.Trace($"CheckAnnotationCreator: Exception - {ex.Message}"); throw new InvalidPluginExecutionException("An error occurred in the CheckAnnotationCreator workflow activity.", ex); } } }
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 70 Super User 2025 Season 2
Gerardo RenterÃa Ga... 33 Most Valuable Professional
Daniyal Khaleel 32 Most Valuable Professional