locked
preventDefault is not working in mscrm 2013 RRS feed

  • Question

  • Dear all i am tring to prevent save in mscrm 2013 through this line getEventArgs().preventDefault() is not workign is still saving the form
    • Edited by anwar_addi Wednesday, December 18, 2013 1:45 PM
    Wednesday, December 18, 2013 11:00 AM

Answers

  • Did you disable auto save settings in System Settings?
     - Click on Dynamics CRM-> Settings tile
     - Click on Settings-> Administration tile
     - Click on System Settings icon
     - Set “No” to “Enable auto save on all forms” under “Select the default save option for forms”
     
    Check JavaScript code as below.

    function preventAutoSave(econtext) {

        var eventArgs = econtext.getEventArgs();

        if (eventArgs.getSaveMode() == 70) {

            eventArgs.preventDefault();

        }
    }

    1. In the Form Properties window, in the Event Handlers section, set Event to OnSave.
    2. Click on Add  and choose the above code written JavaScript resource file
    3. In the Handler Properties window, set Library to the web resource you added in the previous step.
    4. Type ‘preventAutoSave’ in the Function field. This is case sensitive. Do not include quotation marks.
    5. Make sure that Enabled is checked.
    6. Check Pass execution context as first parameter.
    7. Click OK to close the Handler Properties dialog.

    • Edited by VSomireddy Thursday, December 26, 2013 9:38 PM formatting
    • Marked as answer by anwar_addi Friday, February 21, 2014 2:08 PM
    Thursday, December 26, 2013 9:36 PM

All replies

  • Hi Anwar,

    Can you kindly verify if you have checked the Pass Execution Context as first Parameter box while specifying the save event handler.

    Regards,

    Shraddha Dhingra

    http://blogs.msdn.com/b/shraddha_dhingra/

    Thursday, December 19, 2013 8:30 AM
  • Yes i have checked it and here is my code

    function FrmOnSave(prmContext) {

        var wod_SaveMode, wod_SaveEventVal; 
        wod_SaveEventVal = 58; 
     

     
        if (prmContext != null && prmContext.getEventArgs() ) 


     
            wod_SaveMode = prmContext.getEventArgs().getSaveMode();


            if (wod_SaveMode == wod_SaveEventVal ) 

                

    prmContext.getEventArgs().preventDefault(); 

    }

    }
    • Edited by anwar_addi Thursday, December 19, 2013 10:17 AM
    Thursday, December 19, 2013 10:11 AM
  • Hi Anwar,

    Please check below condition is satisfying or not. In 2013 Auto save mode will also fire, may be in that condition it is saving.

      if (wod_SaveMode == wod_SaveEventVal ) 

    thanks,

    sravan.J

    Please Mark it as answer if it helps in resolving your query

    Thursday, December 19, 2013 12:47 PM
  • Hi sravan ;

    it is satisfying the condition

    Thursday, December 19, 2013 12:57 PM
  • Hi Anwar,

    I think you are using Mark As Complete to run the above script.

    I tried it out in CRM 2013 environment. And it is properly cancelling the save as well as mark as complete event.

    Then later when auto save event fires it saves the form with the new values.

    Could you please try by disabling the auto save event.

    function preventAutoSave(econtext) {
        var eventArgs = econtext.getEventArgs();
        if (eventArgs.getSaveMode() == 70) {
            eventArgs.preventDefault();
        }
    }

    Regards,

    Shraddha Dhingra

    http://blogs.msdn.com/b/shraddha_dhingra/

    Thursday, December 19, 2013 3:43 PM
  • Hi anwar,

    while debugging this condition will satisfy. I think when auto save will fire at that time that record is saving. Once disable autosave, then you can test

    Thanks,

    sravan.J

    • Proposed as answer by sravan J Wednesday, October 8, 2014 8:53 AM
    Friday, December 20, 2013 6:56 AM
  • Did you disable auto save settings in System Settings?
     - Click on Dynamics CRM-> Settings tile
     - Click on Settings-> Administration tile
     - Click on System Settings icon
     - Set “No” to “Enable auto save on all forms” under “Select the default save option for forms”
     
    Check JavaScript code as below.

    function preventAutoSave(econtext) {

        var eventArgs = econtext.getEventArgs();

        if (eventArgs.getSaveMode() == 70) {

            eventArgs.preventDefault();

        }
    }

    1. In the Form Properties window, in the Event Handlers section, set Event to OnSave.
    2. Click on Add  and choose the above code written JavaScript resource file
    3. In the Handler Properties window, set Library to the web resource you added in the previous step.
    4. Type ‘preventAutoSave’ in the Function field. This is case sensitive. Do not include quotation marks.
    5. Make sure that Enabled is checked.
    6. Check Pass execution context as first parameter.
    7. Click OK to close the Handler Properties dialog.

    • Edited by VSomireddy Thursday, December 26, 2013 9:38 PM formatting
    • Marked as answer by anwar_addi Friday, February 21, 2014 2:08 PM
    Thursday, December 26, 2013 9:36 PM
  • even putting the javascript on form the form is still saving but i change something and try to mark as completed then it works but if i open the form and mark as completed the form gets saved
    Monday, January 6, 2014 7:55 PM
  • i can not disabled auto save functionality 
    Monday, January 6, 2014 8:05 PM
  • Hi Anwar,

    I'm also facing the same issue as yours. Can you please let me know what exactly you did to resolve the issue ?

    I've put the conditions of PreventDefault() on Lead Qualification. When I update any field on form randomly and then click Qualify Lead then the Scripts works perfectly fine. But after saving the update on form when I again click the Qualify Button on the Lead, the PreventDefault() doesn't work !!!

    I've even checked with isDefaultPrevented() which mentions value 'True' in both the cases but doesn't happen so.

    It would be very helpful if you could share your solution here.


    Thanks, Ashwani

    Monday, March 31, 2014 2:52 PM