Dynamics 365 Client API Changes Continued – GlobalContext and FormContext

2 Comments

Following on from a previous post where we introduce changes to the Client API and form context, let’s look more at using this in order to move from the deprecated Xrm.Page.

Using a similar example, we will pass the context from the OnChange event of our Fax field on the page our JavaScript function (we will reuse the OnLoad function):

function DoLoad(executionContext) {
var formContext = executionContext.getFormContext();
}

From here, we can put a breakpoint on the web resource when it loads to play with the executionContext that is passed in:

Our page:

Let’s look at some methods.

formContext.data.entity.getEntityName

Old method: Xrm.Page.data.entity.getEntityName

formContext.data.entity.getId

Old method: Xrm.Page.data.entity.getId

formContext.data.entity.getIsDirty

Old method: Xrm.Page.data.entity.getIsDirty

formContext.data.entity.getDataXml

This is migrated from Xrm.Page.data.entity.getDataXml.

formContext.data.entity.save()

Old method: Xrm.Page.data.entity.save

Saves the form.

formContext.getAttribute

When dealing with Attributes, we can use formContext.getAttribute. Some examples include:

  • getValue
  • getAttributeType
  • getMaxLength
  • setValue

Xrm.Utility.getGlobalContext

From a Global perspective, Xrm.Page.context moves to the new Xrm.Utility.getGlobalContext. Running this in the debugger:

We can compare this to the old method:

The following are several methods from Xrm.Utility.getGlobalContext:

  • globalContext.userSettings.getTimeZoneOffsetMinutes() (Old: Xrm.Page.context.getTimeZoneOffsetMinutes)
  • globalContext.userSettings.userId (Old: Xrm.Page.context.getUserId)
  • globalContext.userSettings.languageId (Old: Xrm.Page.context.getUserLcid)
  • globalContext.userSettings.userName (Old: Xrm.Page.context.getUserName)
  • globalContext.userSettings.securityRoles (Old: Xrm.Page.context.getUserRoles)
  • globalContext.organizationSettings.isAutoSaveEnabled (Old: Xrm.Page.context.getIsAutoSaveEnabled)
  • globalContext.organizationSettings.languageId (Old: Xrm.Page.context.getOrgLcid)
  • globalContext.organizationSettings.uniqueName (Old: Xrm.Page.context.getOrgUniqueName)

 

THANKS FOR READING. BEFORE YOU LEAVE, 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

 

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

 

2 Responses to Dynamics 365 Client API Changes Continued – GlobalContext and FormContext

Leave a Reply

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