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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Plugin which runs after record save

(0) ShareShare
ReportReport
Posted on by 85

Hi,

I am creating a plugin which runs after saving a record.

1. now how do I get a particular field of the record which is being saved.

2. how to get records of another entity based on some condition ?

public void Execute(IServiceProvider serviceProvider)
        {

            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService orgService = factory.CreateOrganizationService(context.UserId);
            ITracingService traceService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity entity = context.InputParameters["Target"] as Entity;
                
                // Verify that the target entity represents an account.
                // If not, this plug-in was not registered correctly.
                if (entity.LogicalName != "contact")
                    return;
                
                //logic here
                
            }
        }

I have the same question (0)
  • Verified answer
    OmarZaarour Profile Picture
    1,705 on at

    Hi,

    If my understanding is correct, your plugin runs on the Create message, right? Or also on the update message?

    If it is on the Create Message, then your "entity" will have all the attributes you need. You can get the attribute like this:

    var someAttValue = entity.GetAttributeValue<Type>("logicalNameOfYourAttribute");

    as an example of this, if you want to get the value of an attribute named "abc_name", and it is of type string, you would write:

    var name=entity.GetAttributeValue<string>("abc_name");

    Now, if your plugin is registered on the Update message as well, the "entity" object will only contain the the attributes that got modified only. This means, you would want to issue another call to get the values that are not included in the execution context.

    To get a record of another entity, see the example here docs.microsoft.com/.../use-queryexpression-class

  • RG Student Profile Picture
    85 on at

    Hi Omar,

    Thanks for your response.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 58 Most Valuable Professional

#2
#ManoVerse Profile Picture

#ManoVerse 42

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans