CRM Crate

Using setFocus client API in Dynamics 365 CRM

In this course, we will learn to use setFocus client API in Dynamics 365 CRM. Before we start, make sure to subscribe to CRM Crate.

Using setFocus client API in Dynamics 365 CRM

What is client API reference for model-driven apps?

A. The Client API object model also contains the Xrm.Internal namespace, and use of the objects/methods in this namespace isn’t supported. These objects, and any parts of the HTML Document Object Model (DOM), are subject to change without notice. We recommend that you don’t use these functions or any script that depends on the DOM.
B. Also, while debugging, you may find methods and objects in the Client API object model that aren’t documented. Only documented objects and methods are supported.
C. Most of the client scripting APIs available in this documentation also apply to Dynamics 365 Customer Engagement (on-premises). For a list of client scripting APIs not available for Customer Engagement (on-premises), see Client scripting reference for Dynamics 365 Customer Engagement (on-premises).

Undestanding the setFocus client API (Automatically focus on tab) –

The setFocus client API is used to focus a specific as per the business logic. The users can automatically navigate between the tabs as per the logic defined in the setFocus client API.

Syntax for using setFocus client API

formContext.getControl(arg).setFocus();

JavaScript Code Snippet for setFocus in Dynamics 365 CRM

We will use the setFocus client API during an OnChange event of an entity form. As soon as the user updates the field, the user will get automatically navigated to the tab as specified in the below JavaScript code.

//CRM Crate JavaScript Snippet -
function CallMethod (executionContext) {

//Using the setFocus client API.
var formContext = executionContext.getFormContext();
formContext.ui.tabs.get("WebService").setFocus();
}

Let us now validate the above JavaScript snippet execution in the Dynamics 365 CRM. The below shown record is automatically navigated to the tab “Web Service” when the field “Subscriber” is updated.

Thus we learned to use the setFocus client API in Dynamics 365 CRM form.

2.5 2 votes
Article Rating
Subscribe
Notify of
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Gopal Sharma
3 years ago

Wonderful. Thankd

error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.