When would onSave form event occur in model-driven apps?

By | July 21, 2020

We can use three different functions to save a form:

  • formContext.data.entity.save
  • formContext.data.save
  • formContext.data.refresh(true…)

 

Off the top of your head, do you know which one will result in the “onSave” form event and when?

Those details might not be quite obvious when looking at the documentation for each of the functions separately, but there is a documentation for the onSave event which gives us the answer:

https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/events/form-onsave

image

Notice the difference between formContext.data.entity.save and the other two. Whether onSave will be called or not depends on whether there is unsaved data for those, but it does not matter for the formContext.data.entity.save. It’s one of those strange cases where onSave will actually be called even if there is no changed data to be saved. Which makes it an equivalent of the “save” button (see the first bullet item).

Why would it matter? I am actually having a hard time coming up with the scenarioSmile Except, possibly, if you have some custom logic in the onSave that is supposed to kick in whenever the user clicks “save” button (counting save button clicks? Well…), and that logic might not kick in when formContext.data.save or formContext.data.refresh is used.

Leave a Reply

Your email address will not be published.