web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Access Pre Image On Delete Post Operation Plugin

(0) ShareShare
ReportReport
Posted on by 50

Hi,

I have a Post Operation Delete Plugin (Must be on POST because I have to update counters and don't want to count the delete record)

I had a Pre Image because I need info about the deleted record.

I don't know how to access the Image.

Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Access Pre Image On Delete Post Operation Plugin

    Hi Laurent,

    You can also accept my answer :

    Please make sure you define plugin step following:

    Messages : Delete

    Event Pipeline Stage of Execution : Pre-Validation

    And also don't forget to create 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));
    
                // Obtain the execution context from the service provider.
                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)
                {				
    
                    // Obtain the target entity from the input parameters.
                    Entity entity = (Entity)context.InputParameters["Target"];			
    
                    
                    if (entity.LogicalName != "YourEntityName")  //Need to replace with your entity
                        return;
    				
    				try
    				{
    					if	(context.PreEntityImages != null && context.PreEntityImages.Contains("PreImage"))
    					{
    						 Entity BeforeDeleteEntity = (Entity)context.PreEntityImages["PreImage"]; // Get Pre Image of the entity
    						/// Your Logic Here
    					}
    				
    				 }
                    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;
                    }
    			}
    		}
    	}


  • Michel Gueli Profile Picture
    982 on at
    RE: Access Pre Image On Delete Post Operation Plugin

    Please mark the answer as verified.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Access Pre Image On Delete Post Operation Plugin

    Michel Gueli has posted the solution. You get the entity reference from the context, just not the context entity (as is the case with a regular post no-image plugin).

    The simplest way to get it:

    Entity entity = (Entity)context.PreEntityImages["preimg"];

    "preimg" is the name given to the image when registering your plugin in the plugin registration tool.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Access Pre Image On Delete Post Operation Plugin

    Hi Michel,

    correct me if I am wrong but in the last row it states that post Delete has a preImage available. Of course there is no post image as the record is deleted

  • Suggested answer
    Michel Gueli Profile Picture
    982 on at
    RE: Access Pre Image On Delete Post Operation Plugin
    Message Stage Pre-Image Post-Image
    Create PRE No No
    Create POST No Yes
    Update PRE Yes No
    Update POST Yes Yes
    Delete PRE Yes No
    Delete POST Yes No

    There is a pre-image in the post Stage.

    var preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains("PreImage")) ? context.PreEntityImages["PreImage"] : null;

    "PreImage" is my alias for my pre-image.

     

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Access Pre Image On Delete Post Operation Plugin

    Hi,

    can this help you? community.dynamics.com/.../utilising-pre-post-entity-images-in-a-dynamics-crm-plugin

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#2
Christoph Pock Profile Picture

Christoph Pock 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans