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)
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
Has anyone said if there is a deadline for replacing Xrm.Page with formContext?
Is it possible to use formContext instead of Xrm?