locked
event.returnValue=false; Is not working in CRM 2011 RRS feed

  • Question

  • After validating some fields on the form,if same required fields are empty or some fields not filled according the regular exp. I need to stop Save event.

    I use in my JS

    event.returnValue = false; 

    but not working also I tried

    executionObj.getEventArgs().preventDefault()

    function,but that is also not working.

    Has anyone help me?


    Friday, March 18, 2011 2:34 PM

Answers

  • It should be:
    ExecutionObj.getEventArgs().IsDefaultPrevented()
    with a capital E
    Friday, March 18, 2011 3:31 PM
  • Problem Solved.

        event.returnValue = false;
        //After this line I need to write following
        return false;
    

     Thanks.

    Friday, March 18, 2011 3:32 PM

All replies

  • Your code looks fine: executionObj.getEventArgs().preventDefault();

    Try put in a allert("text"); to make sure the latest code is executed.

    Friday, March 18, 2011 2:58 PM
  • executionObj.getEventArgs().preventDefault(); code part throws an exception.

    I think this line is not executing properly.And event.returnValue=false; command doesn't stop the Save event on the form.

    alert("text"); is not executing after executionObj.getEventArgs().preventDefault();

    I need to stop Save,Save & Close,Save & New event on the form if my validation functions return false.

    Friday, March 18, 2011 3:20 PM
  • It should be:
    ExecutionObj.getEventArgs().IsDefaultPrevented()
    with a capital E
    Friday, March 18, 2011 3:31 PM
  • Problem Solved.

        event.returnValue = false;
        //After this line I need to write following
        return false;
    

     Thanks.

    Friday, March 18, 2011 3:32 PM
  • Yes I missed also upper-lower case status.

    Thanks.

    Friday, March 18, 2011 3:33 PM
  • Problem Solved.

        event.returnValue = false;
        //After this line I need to write following
        return false;
    

     Thanks.

     Hey, I'm trying the same but  am getting an error while I debug ..it says..

                  'return' statement outside of function

     any idea about this ??


    • Edited by Pradeep47 Monday, May 28, 2012 9:01 AM
    Monday, May 28, 2012 8:59 AM
  • Hi Pradeep,

    Could you paste your full code here


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, May 28, 2012 9:09 AM
    Moderator
  • Hello Mahendar

    This is just part of funciton where am tring this code..

      if (Math.round(parseFloat(Xrm.Page.data.entity.attributes.get("estimatedvalue").getValue())) != Math.round(parseFloat(totalcalculatedrevenuefromsplits))) {
                                    //Execute();
            alert("The sum of revenue splits does not match the Estimated Revenue. Please edit the revenue splits to make it equal to the estimated revenue.");
            event.returnValue = false;
            return false;
       }

    I just want to stop save, in case the  validation is found wrong, ie, after error message. 



    • Edited by Pradeep47 Monday, May 28, 2012 9:32 AM
    • Proposed as answer by Pradeep47 Monday, May 28, 2012 1:25 PM
    • Unproposed as answer by Pradeep47 Monday, May 28, 2012 1:26 PM
    Monday, May 28, 2012 9:28 AM
  • Hi,

    Did you try

    function Validation(ExecutionObj)

    {

     if (Math.round(parseFloat(Xrm.Page.data.entity.attributes.get("estimatedvalue").getValue())) != Math.round(parseFloat(totalcalculatedrevenuefromsplits))) {
                                    //Execute();
            alert("The sum of revenue splits does not match the Estimated Revenue. Please edit the revenue splits to make it equal to the estimated revenue.");
            ExecutionObj.getEventArgs().isDefaultPrevented();

       }}

    *make sure to enable "Pass execution context as first parameter" while calling your function on save


    Mahain : Check My Blog
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by Pradeep47 Monday, May 28, 2012 1:26 PM
    Monday, May 28, 2012 9:53 AM
    Moderator
  • Thanks it worked. 
    Monday, May 28, 2012 1:25 PM