Unable to open a quick create form

In our Dynamics 365 instance, we're trying to open a quick create form for an entity called SourceAssessment using the code example here

var thisEntity = {
    entityType: "SourceAssessment",
    id: Xrm.Page.data.entity.getId()
};
var callback = function (obj) {
    console.log("Created new " + obj.savedEntityReference.entityType + " named '" + 

obj.savedEntityReference.name + "' with id:" + obj.savedEntityReference.id);
}
var setName = { name: "Child account of " + Xrm.Page.getAttribute("name").getValue() 

};
Xrm.Utility.openQuickCreate("SourceAssessment", thisEntity, setName).then(callback, function 

(error) {
    console.log(error.message);
});
  • The line Xrm.Page.data.entity.getId() throws

    Uncaught TypeError: Cannot read property 'entity' of null(…)

  • The line Xrm.Page.getAttribute("name").getValue() throws

    Uncaught TypeError: Cannot read property 'getValue' of null(…)

  • The line Xrm.Utility.openQuickCreate("SourceAssessment", thisEntity, setName).then(callback, function (error) { console.log(error.message); }); throws

The entityLogicalName isn't valid. This value can't be null or empty, and it must represent an entity in the organization.

Answers:

Answer

When using the developer console to execute code, you have to first switch to the correct frame, in order to access the Xrm.Page object of the form.

In Chrome you can switch frames here:

enter image description here

The frame you want to be in is usually called customScriptsFrame, and other times it is one of the numbered contentIFrames.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.