Home › Dynamics 365 Customer Engagement (CRM) › Focus on a Tab using JavaScript in Dynamics 365
Dynamics 365 Customer Engagement (CRM) · Feb 28, 2020 · 1 MIN READ

Focus on a Tab using JavaScript in Dynamics 365

Let’s look at JavaScript code to move a user to a specific tab in Dynamics 365 / Power Apps.

Below on the Account record I have these tabs – Summary, Project Price Lists, General etc:

Let’s go to the General tab when something happens, like changing a field value.

The General tab is called Partner_Details:

Here’s the code is below. Be sure to pass the execution context:

[sourcecode language=”CSharp”] function FocusOnTab(executionContext) {
var formContext = executionContext.getFormContext();
formContext.ui.tabs.get("Partner_Details").setFocus();
}
[/sourcecode]

Now we start on the Summary tab:

Run the code, and we’re taken over to the General tab:

 

Carl de Souza
Keep learning. Keep building.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.

Subscribe on YouTube →
Carl de Souza Enterprise Architect at Microsoft · AI Technology Expert

5 Responses to Focus on a Tab using JavaScript in Dynamics 365

  1. Hi Carl, thanks for your post this is great. I have one question. How would it work if I had a page refresh and when successful focus on a specific tab? This is the scenario I have right now. A field change, triggers a page refresh that is needed, but the page refresh brings the user back to the first tab.

  2. UPDATED SCRIPT 2023. navigates based on a conditional option set

    function Setdefaultfocus(executionContext) {
    let formContext = executionContext.getFormContext();
    if (formContext !== null && formContext !== undefined) {
    let rbcRfqOpportunity = formContext.getAttribute(“rbc_rfqopportunity”).getValue();

    if (rbcRfqOpportunity == 1) {
    formContext.ui.tabs.get(“tab_6”).setFocus()
    formContext.ui.tabs.get(“tab_6”).setDisplayState(“expanded”);
    } else {
    formContext.ui.tabs.get(“Summary”).setFocus()
    formContext.ui.tabs.get(“Summary”).setDisplayState(“expanded”);
    }
    }
    }

  3. How does the ‘FocusOnTab’ JavaScript function work in Dynamics 365/Power Apps to move the user to a specific tab? Could you explain the purpose of the ‘getFormContext’ and ‘setFocus’ methods, as well as how the ‘Partner_Details’ tab is identified and targeted within the function?

Leave a Reply

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

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.