Pages

Monday 1 July 2019

Syntax Difference Between CRM2016 and Version 9 (FormContext)

In CRM2016 , the global 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.


CRM2016
function displayName()
{
var firstName = Xrm.Page.getAttribute("new_field1").getValue();
var lastName = Xrm.Page.getAttribute("new_field2").getValue();
console.log(firstName + " " + lastName);

}


Latest Version CRM
function displayName(executionContext)
{
var formContext = executionContext.getFormContext(); // get formContext

// use formContext instead of Xrm.Page
var firstName = formContext.getAttribute("new_field").getValue(); 
var lastName = formContext.getAttribute("new_field").getValue();
console.log(firstName + " " + lastName);

}

No comments:

Post a Comment