RE: Force Refresh after Form Save
Ah, I'm sorry, my answer was partly wrong. The reason you're getting that error is that it's trying to save twice at the same time - once when you click Save and once during the function called onSave.
One option is to change it to formContext.data.refresh(false). This won't save form for the refresh. However, I believe this may refresh BEFORE the save action is completed, meaning you may lose data.
Another option is to use the addOnPostSave method. This adds a function to be called AFTER the save event is completed. For example:
function onSave(executionContext) {
var formContext = executionContext.getFormContext();
formContext.data.entity.addOnPostSave(refreshForm);
}
function refreshForm(executionContext)
{
var formContext = executionContext.getFormContext();
formContext.data.refresh(true);
}
On save, this will add the refreshFrom function the the Post Save event, which will then fire and refresh the form after the save is complete. You can change the (true) to (false) in the refresh method if you don't want the form to save again, but in my experience I often get a pop up asking to save if it's set to (false), so I just leave it at (true).