Run JavaScript When User Clicks On Unified Interface Tab

1 Comment
BEFORE WE START, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

In Dynamics 365 / Power App, we may want to “do something” when a user clicks on a form tab. Let’s look at how we can write a handler to invoke custom code.

In our example, let’s look at the Account form. This form has multiple tabs – Summary, Project Price Lists, General etc. Let’s write code so when a user clicks in and out of the General tab, our code runs:

Edit the form and go to the General tab properties:

We see the tab is actually called Partner_Details. Click OK:

Click to add a new script on the Form Properties:

Click Add:

Create a new JScript, ours called DoAccountStuff.js:

Add the following code. We will call this on the on load of the Account form. Note we are using addTabStateChange to attach our custom function TabClicked to the clicking event:

function OnLoad(executionContext) {
   formContext = executionContext.getFormContext();

   var PartnerDetailsTab = formContext.ui.tabs.get("Partner_Details");
   PartnerDetailsTab.addTabStateChange(TabClicked);
}

function TabClicked() {
   alert("Tab Clicked");
}

Click to Save the Script, and add it to the OnLoad:

Passing the Context:

Now, on the Account form, click on the General tab. We see our script is invoked:

Note we are passing the executionContext, with the form context, which is useful to do something more meaningful in our script.

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

One Response to Run JavaScript When User Clicks On Unified Interface Tab

Leave a Reply

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