{"id":35,"date":"2025-06-25T13:08:16","date_gmt":"2025-06-25T13:08:16","guid":{"rendered":"https:\/\/dandltechnology.com\/?p=35"},"modified":"2025-06-25T13:10:26","modified_gmt":"2025-06-25T13:10:26","slug":"use-the-new-post-save-event","status":"publish","type":"post","link":"https:\/\/dandltechnology.com\/index.php\/2025\/06\/25\/use-the-new-post-save-event\/","title":{"rendered":"Use the new Post Save Event"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>I completed this relatively simple task but noticed when I changed the value on the record and saved, the button wasn&#8217;t visible as expected.  I would refresh my browser and the button appeared.<\/p>\n\n\n\n<p>I didn&#8217;t want this to become a training issue, besides, having to refresh after a save doesn&#8217;t seem too user friendly.<\/p>\n\n\n\n<p>SOLUTION:  Add a Post Save Event and refresh the ribbon.<\/p>\n\n\n\n<p>On form load I added the post save event code.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>var formContext = null;\nfunction onLoad(executionContext) {\n     formContext = executionContext.getFormContext();\n    formContext.data.entity.addOnPostSave(refreshRibbon);\n}<\/code><\/pre>\n\n\n\n<p>refreshRibbon parameter is the function that gets called after a save event is finished.  The code below gets called after the save event.<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>function refreshRibbon() {\n    formContext.ui.refreshRibbon(true);\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t visible as expected. I would refresh [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[8,9],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-d365","category-javascript","tag-d365","tag-javascript"],"_links":{"self":[{"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":4,"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":39,"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/posts\/35\/revisions\/39"}],"wp:attachment":[{"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dandltechnology.com\/index.php\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}