Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM Service Activity - Issue with Javascript on save

Posted on by 390

Hi

I am attempting to stop the service activity form from submitting. I have created this small javascript method that is executed on form save. The last line of the method confirms that the save event has been prevented. However, the form still submits. Is it not possible to prevent form submission on service activities or am I doing something wrong?

function save(context) {
    var saveEvent = context.getEventArgs();
    saveEvent.preventDefault();
    console.log(saveEvent.isDefaultPrevented());
}


 

*This post is locked for comments

  • Tushar2016CRM Profile Picture
    Tushar2016CRM 1,130 on at
    RE: CRM Service Activity - Issue with Javascript on save

    HI

    Please try below code if it might help:

    function (econtext) {

       var eventArgs = econtext.getEventArgs();

       if (eventArgs.getSaveMode() == 70 //autosave

           || eventArgs.getSaveMode() == 1) //manual save or Xrm save

       {

                    //Prevent auto/manual save

               eventArgs.preventDefault();

           

       }

    }

    dynamicscrmgirl.wordpress.com/.../crm-2013-beta-javascript-formcontrol-notifications-and-preventing-autosave

    thanks !

  • 2015crm Profile Picture
    2015crm 390 on at
    RE: CRM Service Activity - Issue with Javascript on save

    Unfortunately the issue still seems to exists after a function name change?

  • 2015crm Profile Picture
    2015crm 390 on at
    RE: CRM Service Activity - Issue with Javascript on save

    Context is already been passed through to the method and isPreventDefault() is returning a value.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: CRM Service Activity - Issue with Javascript on save

    Hello,

    Haven't faced similar issues but try to change name of function to something not-so standard (and potentially system name) like:

    function myOnSaveHandler(){

    //...

    }

  • Tushar2016CRM Profile Picture
    Tushar2016CRM 1,130 on at
    RE: CRM Service Activity - Issue with Javascript on save

    HI ,

    Please check if ur selecting ''Pass execution context * as shown in below link:

    neilparkhurst.com/.../javascript-prevent-save

    Thanks !

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans