Open Entity Form Dynamically From Web Resource

Details

Sometimes, we have a requirement to open the entity form, or I will say, refresh the complete form from a custom dialog. Normally, when we want to refresh the complete form, we use Xrm.Navigation.openForm to open entity form. We can use the following code to open the entity form.

function OpenEntityForm(entityName, entityId) {
    var entityFormOptions = {};
    entityFormOptions["entityName"] = entityName;
    entityFormOptions["entityId"] = entityId;

    // Open the form.
    Xrm.Navigation.openForm(entityFormOptions).then(
        function (success) {
            console.log(success);
        },
        function (error) {
            console.log(error);
        }
    );
}

In the above code, we can pass the entity name and entity ID; it will open entity records. This option works fine if we want to open the entity form using the command button/ribbon button. But let’s say we have a requirement to open an entity form from a custom dialog. Let’s say we have a custom dialog created using an HTML web resource, and when we use this method to open the entity form, it will show you the prompt below.

Error

Normally, we get this prompt when there is any field dirty in the form, and we are trying to navigate without saving the form, but in this case, even though there is no field dirty, we will get this dialog. To avoid this issue, we used the following code to open the entity form.

window.top.location.href = url;

While this is working fine to open entity form, it replaces the current navigation history, so we can’t go back to it. Let me know if anyone has a better option.

Hope it will help someone!

Keep learning and Keep Sharing!

HIMBAP
We are expert in Microsoft Power Platform.