Skip to main content

Notifications

Announcements

No record found.

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 370

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
    ArdantHammer 370 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
    Jercy_vz 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
    James 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
    ArdantHammer 370 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

Announcing Our 2025 Season 1 Super Users!

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

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,401 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans