Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

(Entity)context.InputParameters["Target"]

Posted on by

I have a plugin that triggers on update of a Contact in Dynamics,

If in my plugin i set a new Entity to (Entity)context.InputParameters["Target"] am i right in thinking this entity will now have all of the fields associated to the contact record? or does it only contain the fields that were updated?

When the context.InputParameters["Target"] is EntityReference i retrieve the contact fields i need based on the target.id

Example 

public void Execute(IServiceProvider serviceProvider) {
// Get tracing service for debugging purposes
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

// Get the context of the message
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Confirm that we have a target and that the target is an entity
if (context.InputParameters.Contains("Target")) {
// Get the service to be used for reading/writing to Dynamics
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService dynamicsService = serviceFactory.CreateOrganizationService(context.UserId);

Entity entity;
if (context.InputParameters["Target"] is Entity) {
tracingService.Trace("Contact update plugin is triggerd - Target is Entity");
entity = (Entity)context.InputParameters["Target"];
}

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: (Entity)context.InputParameters["Target"]

    Hi,

    Target will only have list fo fields which are updated.

    You should register Preimage in plugin steps.

    In Code first try to check if field is present in Target get the value else check if field is present in preimage then get the value and proceed.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: (Entity)context.InputParameters["Target"]

    Hi,

    In the post-update operation, we can get the following records.

    1. Target 
      This contains only the field values which are updated in the record. It needs to be called as follows:
      Entity target = (Entity)context.InputParameters["Target"];
    2. Pre-Image
      This contains only the field values before the update operation. It needs to be called as follows:
      Entity preImage= (Entity)context.PreEntityImages["NameGivenWhileImageRegistration"];
    3. Post-Image
      This contains only the field values after the update operation. It needs to be called as follows:
      Entity postImage= (Entity)context.PostEntityImages["NameGivenWhileImageRegistration"];

    The name which is used while registering the pre-image and post-image should be given while fetching the input parameters. I have roughly given here "NameGivenWhileImageRegistration". You can also specify which fields needs to be fetched in the pre and post images while registering the image.

    Please refer the link below for more info.

     

  • Suggested answer
    meelamri Profile Picture
    meelamri 13,204 User Group Leader on at
    RE: (Entity)context.InputParameters["Target"]

    Hi,

    When a record is updated, the target input will only contain the fields that were updated. You need to perform a retrieve if you want to check the other fields.

    Good Luck !!

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