Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Getting Execution Context for JavaScript OnSave Event

(0) ShareShare
ReportReport
Posted on by 372

I am working on a javascript function to provide duplicate detection. I want to prompt the user that there may be a duplicate and provide the option to cancel saving/creating the form. I am encountering a problem canceling the save event. I am attempting to use the execObj.getEventArgs().preventDefault() function but I can't seem to get the execution object to be anything other then null even though I have checked the box to pass the execution context as the first parameter. Here is what I have so far:

_onSave: function (executionContext) {
            Xrm.Utility.confirmDialog("A similar record in case# 6572-2 has been detected. Are you sure you want to create this case?", null,
                function (executionContext)
                {
                    executionContext.getEventArgs().preventDefault();
                })
        }


*This post is locked for comments

  • ArdantHammer Profile Picture
    372 on at
    RE: Getting Execution Context for JavaScript OnSave Event

    It has been awhile since I messed with this and the code has grown over time, but I think this is the root of it. 

    _onSave: function (executionContext) { 
        executionContext.getEventArgs().preventDefault();
        //Add Duplicate Detection Check here
    }



    If you determine it is not a duplicate remove the onSave and save the record.

    FormContext.data.entity.removeOnSave(_onSave);
    FormContext.data.entity.save();


    OR if it is a duplicate I have them open the originating record in another window to review the duplicate. Hope it helps. 

  • Jercy_vz Profile Picture
    86 on at
    RE: Getting Execution Context for JavaScript OnSave Event

    Hello John! Thanks for your researching in this issue. Can you share your code. I'd like to see how it looks like.

    Thanks in advance!

  • James Profile Picture
    2 on at
    RE: Getting Execution Context for JavaScript OnSave Event

    Please ignore this answer. I was too hasty and now the forum won't let me delete the post.

  • Verified answer
    ArdantHammer Profile Picture
    372 on at
    RE: Getting Execution Context for JavaScript OnSave Event

    After some debugging. Found that the execution context does not get passed into the callback function. Which makes sense but means the method for doing what I want to do becomes more involved. Instead, I cancel the on save before triggering the confirmation box. The Confirmation box then removes the on Save event and saves the record or leaves the on Save on so that every time you try to save it cancels the save and prompts you about the potential duplicate. It is not the most elegant solution but it seems to work.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans