Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Using C# plugin how to preserve the previous 'ModifiedOn' value when the statecode changes from 0 (Open) to 1 (Completed) for a entity record?

(0) ShareShare
ReportReport
Posted on by 57

Hi,

I want to use a C# plugin in D365 to preserve the previous 'ModifiedOn' value when the statecode changes from 0 (Open) to 1 (Completed) for a entity record

Please provide a example of how to implement this functionality.

Thanks in advance.

  • RE: Using C# plugin how to preserve the previous 'ModifiedOn' value when the statecode changes from 0 (Open) to 1 (Completed) for a entity record?

    Yeah, I kinda said that already Nya.

  • Suggested answer
    Nya Profile Picture
    Nya 29,058 on at
    RE: Using C# plugin how to preserve the previous 'ModifiedOn' value when the statecode changes from 0 (Open) to 1 (Completed) for a entity record?

    Hi,

    It is recommended to achieve your request with a Flow.

    Here is an example which will output the Modified On field when an opportunity’s Status Reason turns into Won.

     pastedimage1627960539479v1.png

    And when an opportunity is Closed as Won, the Modified On will be output as the following:

     pastedimage1627960545183v2.png

    Of course, you can also create a custom field and fill the field with this value via the flow.

  • RE: Using C# plugin how to preserve the previous 'ModifiedOn' value when the statecode changes from 0 (Open) to 1 (Completed) for a entity record?

    Hi Vivek,

    I would first ask why you want to using a plugin for this? Whether you're using on-prem or cloud D365 (I'm assuming you're referring to D365 CE, not BC and definitely not F&O), plugins should be a last resort.  And if you only want to preserve a single data value like that you could easily create a custom field on the entity for the previous value and have an automated cloud flow in Power Automate that triggers when the ModifiedOn value changes and pushes the previous value to the new field.

    One thing that a lot of people haven't run into with the Horrified UI (ooops, Unified UI), is that, for whatever insane reason, MS architected it using a procedural pattern where plugins sit chronologically on top of each other.  For instance, let's say you develop and deploy this plugin that will obviously tie to pretty much all the major entities like Account, Contact, lead, and so on. Then a few months down the road, for example, you put in another plugin.  Whether that is something you develop or an ISV.  Then, let's say, 6 months after that, you come across a great ISV solution that your org really wants to use but when you test it it conflicts with the first plugin.  So, you need to remove the plugin.  Guess what though?  You can't remove the first one until you remove the SECOND one. And loose whatever data the 2nd one managed.  And this actually happens even with MS' own apps.

    If you want to go to the effort I went through, you can actually see this for yourself.  Start with a vanilla Sales Pro environment.  Add D365 marketing.  Create a plugin that references the major entities like contacts, leads, accounts, etc.  Create some data.  The, add in an ISV solution that also references those entities.  Then, try to remove the Marketing app.  MS support gave up trying to remove the Marketing app (which is THEIR marketing app!) from my environment after 3.5 months of support effort.

    So, that was the first thing.  The second thing is that are you aware that, if you have auditing enabled for the entity, you can access the audit logs through M365 Compliance Center (not D365) and the logs will give you that ModifiedOn date change info?

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,569 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans