We should use the new client APIs mentioned in the Replacement Client API instead of the deprecated ones. for example: Xrm.Page will be replaced by Client API form context (formContext).
Check Microsoft URL
function displayName(executionContext)
{
var formContext = executionContext.getFormContext(); // get formContext
var firstName = formContext.getAttribute("firstname").getValue();
var lastName = formContext.getAttribute("lastname").getValue();
alert(firstName + " " + lastName);
// var ContactObject = executionContext.getFormContext().data.entity;
// var firstNameAttribute=ContactObject.attributes.getByName("firstname");
// var lastNameAttribute=ContactObject.attributes.getByName("lastname");
//if (firstNameAttribute !=null) {var firstName=firstNameAttribute.getValue();}
//if (firstNameAttribute !=null) {lastName=lastNameAttribute.getValue();}
}