Prevent Save and create new on Quick create form in Dynamics 365/ CDS

Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com
Our life as consultants can be quite amusing. Sometimes we have a customer who complains about a simple feature not being present in Dynamics 365 and then when Microsoft finally puts it on the table, we have one customer who does not want that feature itself.


Well, customer is GOD. Can’t complain about it. After all they pay the bills. And here I am going to talk about one such feature – “Save and Create New” feature in Quick create forms.
With the October 2019 preview release of the Unified Interface for model-driven apps in PowerApps we have added an option to quickly save a record and create a new one directly from the Quick Create Form. This new button action will make it much easier for users to quickly add a record, save it and start working on another record of the same type directly from the Quick Create form.”
-Courtesy Powerapps documentation.
 
If you still not finding relevance you can read this article. Basically this is what I am talking about.
image
One fine morning at work, my customer walks up to me and asks me remove the Save & create new button. And guess what! their business case seems to be quite valid. They shall launch a quick create on click of a ribbon button and then the user should be allowed to create only one record. Quite reasonable right?
I did a bit of search and found that this behavior cannot be removed. So obviously the next choice is to stop the “Save & Create New” event. And guess what. Microsoft allows you to distinguish between “Save and Close” and “Save & Create New” click. You can do that using our very old getSaveMode() function of save event argument. Will come to the code in a bit.
So basically when the Save & Create New button is clicked, user should be informed – “Save &Create New functionality is not allowed.”. And it should be without any pop-ups which our customer seriously dislikes.
So here is our final solution. I write a simple JavaScript and put it on the Quick create form and then hide it on the form.
Then I go ahead and add the below on save of the lead quick create form.

function leadQuickCreateSave(e) {
    var fc = e.getFormContext();
    var args = e.getEventArgs();
    var saveMode = args.getSaveMode();
   if (saveMode === 59) { // save and create new
       fc.ui.setFormNotification("STOP_SAVE", "ERROR", "Save & Create New functionality is not allowed.");
       args.prevenDefault();
    }
}

And now when everything is published, I just try to use the “Save & Create New” functionality and it work’s just great!
image
Hope this helps!
Debajit Dutta
(Microsoft MVP)