Skip to main content

Notifications

Microsoft Dynamics CRM forum
Suggested answer

How to clear dirty fields in D365 CE

Posted on by 5

I'm trying to clear the dirty fields in Microsoft Dynamics CRM using a script, but I haven't been able to find a solution for it.

can anyone please advise on how I can clear the dirty fields in CRM using a script?

Thank You

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 Moderator on at
    RE: How to clear dirty fields in D365 CE

    Hi Vaish03,

    Take a look at this article for dirty field operations: https://carldesouza.com/checking-isdirty-dynamics-365-using-javascript/ 

  • Suggested answer
    Ray Profile Picture
    Ray 1,477 on at
    RE: How to clear dirty fields in D365 CE

    Can you explain what "clear the dirty field" means?

    If you want to set the dirty field value to null, then you can use this code:

    function clearDirtyFieldValue(executionContext) {
        var formContext = executionContext.getFormContext();
        var myField = formContext.getAttribute("SomeField").getValue();
        // if the field is dirty, clear it
        if (myField.getIsDirty()) {
            myField.setValue(null);
        }
    }

    If you want to control whether data from the dirty field will be submitted when the record is saved, then you can use this code:

    function ignoreDirtyField(executionContext) {
        var formContext = executionContext.getFormContext();
        var myField = formContext.getAttribute("SomeField").getValue();
        if (myField.getIsDirty()) {
            myField.setSubmitMode("never");
        }
    }

    reference:

    getIsDirty

    setSubmitMode

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans