When building applications in Power Apps (Model-driven apps), providing visual feedback during long-running operations enhances the user experience. Power Apps offers a built-in showProgressIndicator function that makes it easy to display a loading animation while background processes run.

JavaScript
Xrm.Utility.showProgressIndicator(message)

This will show a progress indicator as below –

power apps loading animation

You can update the loading message by invoking the same function again with a new message, seamlessly refreshing the existing indicator on the UI.

Ensure that you initiate your long-running task asynchronously after calling showProgressIndicator, as the UI updates asynchronously. If your task runs synchronously, it may block the UI thread, preventing the loading indicator from appearing as expected.

The progress indicator will block the UI until closed. Use the following code to hide the loading animation.

JavaScript
Xrm.Utility.closeProgressIndicator()

For additional information, refer to the official documentation here.