Dynamics 365 – How to get and use formContext

The formContext is a part of executionContext and it replaces deprecated Xrm.Page starting from Version 9.

Xrm.Page object was used to represent a form or an item on the form. With the latest version, the Xrm.Page object is deprecated, and you should use the getFormContext method of the passed in execution context object to return reference to the appropriate form or an item on the form.

from Client API form context – Microsoft Docs

How to pass executionContext to a Javascript function?

For your registered form events you need to check “Pass execution context as first parameter”.

How to get and use formContext in Javascript code?

You can get the fornContext with using getFormContext() function on executionContext parameter.

function FormContextTest(executionContext) {
var formContext = executionContext.getFormContext();
var attr1 = formContext.getAttribute("attr1").getValue();
var entityId = formContext.data.entity.getId();
var formType = formContext.ui.getFormType();
formContext.getControl("attr1").setNotification(notification, "attr1Notification");

One thought on “Dynamics 365 – How to get and use formContext

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s