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
                
            }
        }

  • RG Student Profile Picture
    85 on at
    RE: Plugin which runs after record save

    Hi Omar,

    Thanks for your response.

  • Verified answer
    OmarZaarour Profile Picture
    1,705 on at
    RE: Plugin which runs after record save

    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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 57

#3
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 53 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans