Please wait, loading...

 

Migration from Legacy WebClient to UCI – Deprecated Javascript (Client Api) Collection Book , Replace Deprecated Client API To New and latest Client Api’s

August 22, 2020

Most of us are already using updated client API and replacing example like xrm.page to FormContext, Below is

1. How to replace Deprecated Client API Javascript with New

2. Full Deprecated to New client API Table

There are some big changes in Client API and most of them are as below

  • Execution Context: Context of any item on the form (Xrm.Page)
  • Global Context: utility to retrieve org Information example, userID e.t.c  (Xrm.utility)
  • Deprecated Client Apis and Intrrotucing some new

We will Divide the post in 2 parts

  1. Replace Deprecated Client API To New and latest Client Api’s
  2. Full Deprecated Client API vs new and Latest Client API’S Table

Check1: How to Replace Deprecated Client Apis to New

  1. First approach is to use Upgrade examiner, please check out our last blog as below how to use Fast track and use upgrade examiner as a starter.

    Click Here: http://microsoftdynamics.in/2020/07/16/migration-from-legacy-webclient-to-uci-ask-for-fasttrack-and-upgrade-examiner-not-confident-on-transition-ask-microsoft/

  2. Once you changed the latest client API’s there is a major change with Xrm.Page
    -> 1st enable checkbox ” Pass execution context as the first Parameter -> ExecutionContext is Automatically passed as 1st parameter as below

Check2: Full Deprecated Client API vs new and Latest Client API'S Table

Objective Using Xrm.Page (Deprecated Client API) Using formContext (Replacement Client API)
Simple JavaScript function function demoFunction(){ } function demoFunction(eContext){
//Get form context
var formContext = eContext.getFormContext();
}
Disable/lock field, “addRegions”, for selection Xrm.Page.getControl("addRegions").
setDisabled(true);
formContext.getControl("addRegions").
setDisabled(true);
Enable/unlock field, “addRegions”, for selection Xrm.Page.getControl("addRegions").
setDisabled(false);
formContext.getControl("addRegions").
setDisabled(false);
Hide field, “addRegions” Xrm.Page.getControl("addRegions").
setVisible(false);
formContext.getControl("addRegions").
setVisible(false);
Show field, “addRegions” Xrm.Page.getControl("addRegions").
setVisible(true);
formContext.getControl("addRegions").
setVisible(true);
Get lookup field “region”, and its properties var regionLookup = Xrm.Page.
getAttribute("region").getValue();
if (regionLookup != null) {
var name = regionLookup[0].name;
var guid = regionLookup[0].

id.slice(1, -1);
var entityType =

regionLookup[0].entityType;
}
var regionLookup = formContext.
getAttribute("region").getValue();
if ( regionLookup != null) {
var name = regionLookup[0].name;
var guid = regionLookup[0].

id.slice(1, -1);
var entityType =

regionLookup[0].entityType;
}
Remove option, 15220000, from ‘showRegions’ option set. Xrm.Page.getControl("showRegions").
removeOption(15220000);
formContext.getControl("showRegions").
removeOption(15220000);
Add option, 15220001 (with text: ‘Africa’), to ‘showRegions’ option set. Xrm.Page.getControl("showRegions").
addOption({
value:15220001,
text:'Africa'});
formContext.getControl("showRegions").
addOption({
value:15220001,
text:'Africa'});
Show tab, with logical name “regionsTab” Xrm.Page.ui.tabs.get("regionsTab").
setVisible(true);
formContext.ui.tabs.get("regionsTab").
setVisible(true);
Hide tab, with logical name “regionsTab” Xrm.Page.ui.tabs.get("regionsTab").
setVisible(false);
formContext.ui.tabs.get("regionsTab").
setVisible(false);
Show section “regionsTab_regSection”, located in tab “regionsTab” Xrm.Page.ui.tabs.get("regionsTab").
sections.get("regionsTab_regSection").
setVisible(true);
formContext.ui.tabs.get("regionsTab").
sections.get("regionsTab_regSection").
setVisible(true);
Hide section “regionsTab_regSection”, located in tab “regionsTab” Xrm.Page.ui.tabs.
get("regionsTab").sections.
get("regionsTab_regSection").
setVisible(false);
formContext.ui.tabs.
get("regionsTab").sections.
get("regionsTab_regSection").
setVisible(false);
Count number of records on sub-grid called “demo-grid” var count = Xrm.Page.
getControl("demo-grid").getGrid().

getTotalRecordCount();
var count = formContext.
getControl("demo-grid").getGrid().
getTotalRecordCount();
Deprecated Client API Replacement Client API Comments
Xrm.Page Forms: ExecutionContext.getFormContext
Commands: Send it as the PrimaryControl parameter
Use of the Xrm.Page object as a static access to the primary form context is still supported to maintain backward compatibility with the existing scripts. Based on the feedback, we understand that the usage of Xrm.Page is high, and it won’t be removed as soon as some other client API methods listed in this section. We encourage you to use the new way of getting form content where possible. More information: Client API form context
Although Xrm.Page is deprecated, parent.Xrm.Page will continue to work in case of HTML web resources embedded in forms as this is the only way to access the form context from the HTML web resource.
Xrm.Page.context Xrm.Utility.getGlobalContext Allows access to the global context without going through the form context.
Xrm.Page.context.getQueryStringParameters formContext.data.attributes The formContext.data.attributes API will make retrieval of non-entity bound data consistent across entity forms, metadata-driven dialogs, and task-based flows. The data will be a combination of custom values sent using the query string and what was specified in the parameters in the openForm method.
Xrm.Page.context.getTimeZoneOffsetMinutes globalContext.userSettings.getTimeZoneOffsetMinutes Moved to globalContext.userSettings
Xrm.Page.context.getUserId globalContext.userSettings.userId Moved to globalContext.userSettings
Xrm.Page.context.getUserLcid globalContext.userSetings.languageId Moved to globalContext.userSettings
Xrm.Page.context.getUserName globalContext.userSettings.userName Moved to globalContext.userSettings
Xrm.Page.context.getUserRoles globalContext.userSettings.securityRoles Moved to globalContext.userSettings
Xrm.Page.context.getIsAutoSaveEnabled globalContext.organizationSettings.isAutoSaveEnabled Moved to globalContext.organizationSettings
Xrm.Page.context.getOrgLcid globalContext.organizationSettings.languageId Moved to globalContext.organizationSettings
Xrm.Page.context.getOrgUniqueName globalContext.organizationSettings.uniqueName Moved to globalContext.organizationSettings
Xrm.Page.data.entity.getDataXml No change in the method, but use “typename” instead of type for lookup attributes.
GridRow.getData GridRow.data GridRow is essentially a form context. This change unifies the interface of GridRow with formContext.
GridRowData.getEntity GridRowData.entity GridRowData is form data. This change unifies the interface of GridRowData with formContextData.
Xrm.Mobile.offline Xrm.WebApi.offline Moved the offline-related methods under Xrm.WebApi.offline
parent.Xrm Use one of the following:

a) Use a custom control created using Power Apps component framework instead of HTML web resources.

b) On forms, use the getContentWindow method of the web resource control.

c) If the getContentWindow method doesn’t work, you can use parent.Xrm to get to the Xrm object inside an HTML web resource. If the HTML web resource is opened in a new window then you should use opener.Xrm instead.

Earlier: An HTML web resource may interact with the Xrm.Page or Xrm.Utility objects within the form by using parent.Xrm.Page or parent.Xrm.Utility.

Now: parent.Xrm.* will work if the HTML web resource is loaded in a form container. It won’t work for HTML web resources that are stand alone, or referenced from the site map or any other places.

NOTEparent.Xrm will be removed after the removal of the ClientGlobalContext.js.aspx page; dates yet to be announced.

addOnKeyPress Use a custom control created using Power Apps component framework
fireOnKeyPress Use a custom control created using Power Apps component framework
removeOnKeyPress Use a custom control created using Power Apps component framework
showAutoComplete Use a custom control created using Power Apps component framework
hideAutoComplete Use a custom control created using Power Apps component framework
Xrm.Utility.alertDialog Xrm.Navigation.openAlertDialog The new signature is consistent with other APIs (openForm) and takes a new set of parameters for flexibility.
Xrm.Utility.confirmDialog Xrm.Navigation.openConfirmDialog The new signature is consistent with other APIs (openForm) and takes a new set of parameters for flexibility.
Xrm.Utility.getBarcodeValue Xrm.Device.getBarcodeValue Moving device-related actions to Xrm.Device
Xrm.Utility.getCurrentPosition Xrm.Device.getCurrentPosition Moving device-related actions to Xrm.Device
Xrm.Utility.isActivityType Xrm.Utility.getEntityMetadata The isActivityType method is synchronous so it was suitable for ribbon rules. However, the replacement method, getEntityMetadata, is asynchronous, and is not suitable for ribbon rules.
Xrm.Utility.openEntityForm Xrm.Navigation.openForm Moving navigation actions to Xrm.Navigation
Xrm.Utility.openQuickCreate Xrm.Navigation.openForm Moving navigation actions to Xrm.Navigation
Xrm.Utility.openWebResource Xrm.Navigation.openWebResource Moving navigation actions to Xrm.Navigation
Note: This API returns VOID in Unified Interface.
globalContext.organizationSettings.baseCurrencyId globalContext.organizationSettings.baseCurrency The replacement method lets you access the display name along with the ID of transaction currency.
globalContext.userSettings.securityRoles globalContext.userSettings.Roles The replacement method lets you access the display name along with the ID of the security roles.
globalContext.userSettings.transactionCurrencyId globalContext.userSettings.transactionCurrency The replacement method lets you access the display name along with the ID of transaction currency.
getData and setData for Silverlight web resources None Silverlight is no longer supported. These methods won’t be available after October, 2020.
formContext.data.entity.save formContext.data.save
ClientGlobalContext.js.aspx None The ClientGlobalContext.js.aspx page is built on the legacy web client infrastructure. As the legacy web client is deprecated and scheduled to be unavailable effective December 1, 2020, the ClientGlobalContext.js.aspx page will also be removed along with the legacy web client on December 1, 2020.
getObject getContentWindow

Reference: https://docs.microsoft.com/en-us/power-platform/important-changes-coming#some-client-apis-are-deprecated

https://i0.wp.com/microsoftdynamics.in/wp-content/uploads/2020/04/Microsoftdynamics365.png?fit=640%2C651
Microsoft Dynamics Community Profile

Learn more