web
You’re offline. This is a read only version of the page.
close
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 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

I have the same question (0)
  • Verified answer
    ArdantHammer Profile Picture
    372 on at

    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.

  • James Profile Picture
    2 on at

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

  • Jercy_vz Profile Picture
    86 on at

    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!

  • ArdantHammer Profile Picture
    372 on at

    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. 

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans