Use the new Post Save Event

I recently had a simple requirement which was to show a button on the form ribbon and make its visibility based on field values on the current record.

I completed this relatively simple task but noticed when I changed the value on the record and saved, the button wasn’t visible as expected. I would refresh my browser and the button appeared.

I didn’t want this to become a training issue, besides, having to refresh after a save doesn’t seem too user friendly.

SOLUTION: Add a Post Save Event and refresh the ribbon.

On form load I added the post save event code.

var formContext = null;
function onLoad(executionContext) {
     formContext = executionContext.getFormContext();
    formContext.data.entity.addOnPostSave(refreshRibbon);
}

refreshRibbon parameter is the function that gets called after a save event is finished. The code below gets called after the save event.

function refreshRibbon() {
    formContext.ui.refreshRibbon(true);
};

Comments

Leave a Reply

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