locked
How to mimic save button behaviour RRS feed

  • Question

  • Hi,

     

    I'm kind of new to MSCRM development so I need to ask a question that I can't figure out.

    Actually I need to achieve two things:

    * Add a javascript method to the standard "save entity" button that executes before or after the entity is saved on the form.

    * Add a new button that does exactly what the standard save button does in the entity. So far I have been able to add the new button (using customizations.xml) and make it call a custom javascript method so all I need to know is how to implement a javascript that saves the form.

     

    I'd appreciate any help and suggestions!

     

     

    Monday, November 21, 2011 9:12 AM

Answers

  • Dynamics CRM provides the ability to write scripts on the OnSave event. This code written here is fired before the data is sent to the database for the save to be processed. You generally write any code that validates the data before it is sent to the database.

    If you want to perform any action after the data is saved, you could also try out Plugins or Workflows that allow you to trap the before save and after save (plugin) events. In case of Workflows, you can write code that executes after the record is saved.

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Monday, November 21, 2011 9:17 AM
    • Marked as answer by Tobias Åkerlund Monday, November 21, 2011 1:24 PM
    Monday, November 21, 2011 9:17 AM
  • Using the getSaveMode() from the context.getEventArgs should let you identify the button that was clicked.

    Check the SDK for further details

    ExecutionObj.getEventArgs().getSaveMode()

     

    Entity Event Mode Value

    All

    Save

    1

    All

    Save and Close

    2

    All

    Save and New

    59

    Activities

    Save as Completed

    58

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Monday, November 21, 2011 10:27 AM
    • Marked as answer by Tobias Åkerlund Monday, November 21, 2011 1:24 PM
    Monday, November 21, 2011 10:27 AM

All replies

  • Dynamics CRM provides the ability to write scripts on the OnSave event. This code written here is fired before the data is sent to the database for the save to be processed. You generally write any code that validates the data before it is sent to the database.

    If you want to perform any action after the data is saved, you could also try out Plugins or Workflows that allow you to trap the before save and after save (plugin) events. In case of Workflows, you can write code that executes after the record is saved.

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Monday, November 21, 2011 9:17 AM
    • Marked as answer by Tobias Åkerlund Monday, November 21, 2011 1:24 PM
    Monday, November 21, 2011 9:17 AM
  • Thanks, I found now where to hook up my javascript method. Do you know how I can see which save-button caused this? I only want my excute my script if it was the "save and close" button that was clicked.
    Monday, November 21, 2011 10:11 AM
  • Using the getSaveMode() from the context.getEventArgs should let you identify the button that was clicked.

    Check the SDK for further details

    ExecutionObj.getEventArgs().getSaveMode()

     

    Entity Event Mode Value

    All

    Save

    1

    All

    Save and Close

    2

    All

    Save and New

    59

    Activities

    Save as Completed

    58

    HTH

    Sam


    Web: http://www.inogic.com
    Blog: http://inogic.blogspot.com
    Email: news@inogic.com
    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    • Proposed as answer by Sam - Inogic Monday, November 21, 2011 10:27 AM
    • Marked as answer by Tobias Åkerlund Monday, November 21, 2011 1:24 PM
    Monday, November 21, 2011 10:27 AM
  • Excellent, worked fine! Thanks!
    Monday, November 21, 2011 1:23 PM