In this episode of Low to Pro, Ace Phillips dives into the intricacies of customizing the OnSave behavior in Power Apps using JavaScript. This tutorial is designed for developers looking to enhance their model-driven apps by controlling how data is processed and saved within Dataverse.
Ace presents a common scenario: entering contractor data into Dataverse, where a field must concatenate first name, last name, and contract number. While Power Automate flows could handle this post-save, Ace demonstrates how to prefill and manipulate this data using JavaScript before the record is saved.
Ace introduces a custom JavaScript file containing a function pw.lowToPro.checkSaveType that determines the save type and executes logic accordingly.
After setting up the handler and publishing the form, Ace demonstrates how to test both save types. He explains the concept of "dirty records"—changes not yet saved to the database—and how they trigger the OnSave logic.
Multiple handlers can be added to the OnSave event. They execute in order, allowing developers to chain behaviors like checking save type and then navigating to another page.
In the OnLoad script, Ace checks if the form is new and conditionally adds the OnSave behavior. Regardless of form type, the PostSave logic is always executed after saving.
This function dynamically sets a field value by joining multiple fields with a specified separator. Parameters include:
Ace wraps up by encouraging viewers to explore more about the Client API and event handling in Power Apps. He invites users to connect via https://pragmaticworks.com for mentoring or to explore additional training resources like the "Learn with the Nerds" series.
Don't forget to check out the Pragmatic Works' on-demand learning platform for more insightful content and training sessions on Power Apps and other Microsoft applications. Be sure to subscribe to the Pragmatic Works YouTube channel to stay up-to-date on the latest tips and tricks.