Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Pre Image for delete message

Posted on by 75

Messages : Delete

Event Pipeline Stage of Execution : Pre-Validation

Pre Image pre image under step

public class DeletePlugin: IPlugin
	{
		
        public void Execute(IServiceProvider serviceProvider)
		{
            //Extract the tracing service for use in debugging sandboxed plug-ins.
            ITracingService tracingService =
                (ITracingService)serviceProvider.GetService(typeof(ITracingService));

           
            IPluginExecutionContext context = (IPluginExecutionContext)
                serviceProvider.GetService(typeof(IPluginExecutionContext));

            // The InputParameters collection contains all the data passed in the message request.
            if (context.InputParameters.Contains("Target") &&
                context.InputParameters["Target"] is Entity)
            {				

                
                Entity entity = (Entity)context.InputParameters["Target"];
tracingService.Trace(" exists ");
if (entity.LogicalName != "contact") 
try {
if (context.PreEntityImages != null && context.PreEntityImages.Contains("PreImage")) {
Entity BeforeDeleteEntity = (Entity)context.PreEntityImages["PreImage"];
} }
catch (FaultException<OrganizationServiceFault> ex) {
throw new InvalidPluginExecutionException("An error occurred in the FollowupPlugin plug-in.", ex);
}
catch (Exception ex) {
tracingService.Trace("FollowupPlugin: {0}", ex.ToString()); throw; }
}
else{
tracingService.Trace("not exists ");

}
} }

Result is not exists

I would like to get entity fileds 

*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Pre Image for delete message

    Hello,

    context.InputParameters["Target"] is Entity for delete plugin will always return false

    context.InputParameters["Target"] is EntityReference is the way to go.

    Also you will have to rewrite line

    Entity entity = (Entity)context.InputParameters["Target"];

    to line

    EntityReference entity = (EntityReference)context.InputParameters["Target"];

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.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans