locked
Javascript to stop a form being created RRS feed

  • Question

  • Hi guys,

    Similar to the javascript stopping the saving of a form is there some code that can be used to stop the creation of a form?

    Heres my scenario:

    I have a one to many relationship from account to account plan (a new entity that I have added), this is visible from the account form using the link in the left hand menu of the account screen.

    When a user clicks on the new button I run some code:

    if (countADP >=1)
      {
       alert("Active ADP already exists, please update that one or deactivate before creating a new one");
       }

    This pops up an alert telling the user that an active record already exists but can I add some code that will close the window too?

    Thanks for any help

    Bharat

    Wednesday, September 21, 2011 1:54 PM

Answers

  • It might be easier to move your check and alert onto the onload event of the account plan form, you can then use window.close(); to automatically close the new form if the active adp already exists.

     


    Paul Dowman, CRM Developer


    Hi Paul,

     

    That seems to work well but I get the dreaded "Are you sure you want to navigate away from this page?" message from IE....

    Im asuuming you cant use sendkeys to send an Enter stoke to the application can you?

     

    Bharat

    • Marked as answer by BharatP Wednesday, September 21, 2011 4:34 PM
    Wednesday, September 21, 2011 2:58 PM
  • In 4.0 you can get rid of that alert by calling:

    crmForm.detachCloseAlert();
    
    

    I haven't tried it in 2011 (it would be unsupported) but it might be possible.


    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
    • Marked as answer by BharatP Wednesday, September 21, 2011 4:34 PM
    Wednesday, September 21, 2011 4:06 PM

All replies

  • It might be easier to move your check and alert onto the onload event of the account plan form, you can then use window.close(); to automatically close the new form if the active adp already exists.

     


    Paul Dowman, CRM Developer
    Wednesday, September 21, 2011 2:41 PM
  • It might be easier to move your check and alert onto the onload event of the account plan form, you can then use window.close(); to automatically close the new form if the active adp already exists.

     


    Paul Dowman, CRM Developer


    Hi Paul,

     

    That seems to work well but I get the dreaded "Are you sure you want to navigate away from this page?" message from IE....

    Im asuuming you cant use sendkeys to send an Enter stoke to the application can you?

     

    Bharat

    • Marked as answer by BharatP Wednesday, September 21, 2011 4:34 PM
    Wednesday, September 21, 2011 2:58 PM
  • In 4.0 you can get rid of that alert by calling:

    crmForm.detachCloseAlert();
    
    

    I haven't tried it in 2011 (it would be unsupported) but it might be possible.


    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
    • Marked as answer by BharatP Wednesday, September 21, 2011 4:34 PM
    Wednesday, September 21, 2011 4:06 PM
  • In 4.0 you can get rid of that alert by calling:

     

    crmForm.detachCloseAlert();
    
    
    
    

    I haven't tried it in 2011 (it would be unsupported) but it might be possible.

     


    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav

    Im using CRM 4.0 and it worked a treat...Thanks
    Wednesday, September 21, 2011 4:34 PM