Run JavaScript code after record save in D365 CE/Model-driven app

In this blog, we will understand how to run JavaScript code after the record is saved in D365 CE(CRM) or Model-driven Apps.

To execute JavaScript code after the record is saved we need to use PostSave Event.

PostSave Event

  • PostSave event occurs after the OnSave event is complete. This event is used to execute custom logic which needs to be performed after Save actions. 
  • We will use the addOnPostSave method to manage event handlers for this event.

Use Case: In my example, I create a project task record using the quick create form, and when a project task record is created open the newly created project task record.





 var formCustomizations = {  
   runAftersave: function (executionContext) {  
     var formContext = executionContext.getFormContext();;  

   openProjectTaskForm: function (executionContext) {  
     var formContext = executionContext.getFormContext();  
     var taskId =;  

     var entityFormOptions = {};  
     entityFormOptions["entityName"] =;  
     entityFormOptions["entityId"] = taskId.replace("{", "").replace("}", "");  
     entityFormOptions["openInNewWindow"] = true;  

     // Open the form.  
       function (success) {  
         console.log("record opend sucessfully.");  
       function (error) {  
  • Open the Project Task quick create form.
  • Add the above code on the OnSave event of quick create form of Project Task.


I hope you find this helpful!!

Leave a Reply

Your email address will not be published. Required fields are marked *