Client API - Dynamics 365

Client API is a setup of method and object that we use to interact with dynamics 365 form loaded in the browser.


To interact form’s data or manipulate with form data Microsoft has given one client-side API that is known as Client API. These client-side objects are passed to the browser window when we open any dynamics forms.


With the use of client API, we can perform several activities, a few of them as below

  • Read the form data

  • Set the form attribute values

  • Enable/Disable the form elements

  • Show/hide the element

  • Expand/Collapse the tab

  • CRUD operation can be performed

  • Any many more are possible with client-side API


Client API consists of four primary objects. each object is associated with other objects.


executionContext - This object is passed to function by platform, contains all runtime information like logged in user details, form mode, type, etc...


function FormatFirstName(executionContext)

{

var formContext= executionContext.getFormContext();

}


formContext - · The form context will give access to dynamics form’s elements. It again consists two objects.

  • Data object (formContext. getAttribute) – This will give the attribute data. Like reading, setting/re-setting the attribute values.

function FormatFirstName(executionContext)

{

var formContext= executionContext.getFormContext();

var firstName= formContext.getAttribute(“firstname”).getValue();

}


  • UI object – (formContext.ui.controls) : Facilitate to accessing form controls. like, provide the feature to enable/disable, show/hide the controls over forms.

function FormatFirstName(executionContext)

{

var formContext= executionContext.getFormContext();

var firstName= formContext.getControl(“firstname”);

}


gridContext - Use the formContext object to get an instance of the form where the code is executed, and then retrieve the subgrid control on the form. For example, when you know the name of a subgrid control (any dynamics form’s subgrid) can access it using the following code:


function doSomething(executionContext) {

var formContext = executionContext.getFormContext(); // get the form Context

var gridContext = formContext.getControl("Contacts"); // get the grid context

// Perform operations on the subgrid

}


Xrm Object - The Xrm object is globally available to use in your code without having to use the execution context in Client API.




Xrm.Device - Provides methods to use native device capabilities of mobile devices.

Xrm.Encoding - Provides methods to encode strings.

Xrm.Navigation - Provides methods for navigating forms and items in model-driven apps.

Xrm.Panel - Provides a method to display a web page in the side pane of model-driven apps form.

Xrm.Utility - Provides a container for useful methods.

Xrm.WebApi - Provides methods to use Web API to create and manage records and execute Web API actions and functions. Xrm.WebApi.offline: Provides methods to create and manage records in the model-driven apps mobile clients while working in the offline mode. Xrm.WebApi.online: Provides methods to use Web API to create and manage records and execute Web API actions and functions when connected to the server.



Happy Learning..

36 views0 comments