dynamics-crmdynamics-crm-2011dynamics-crm-2013dynamics-crm-onlinepower-platform

Dynamics crm online + Disable autosave in html webresource


I have disabled autosave functionality on my crm form using the below code. However it still triggers the save function in my html webresource.

//Javascript on the Form onsave

let eventArgs = context.getEventArgs();

if (eventArgs.getSaveMode() == 70)
{
    eventArgs.preventDefault();
}

I am using Vue.js as backend for the html webresource. below is the code i have written:

//Javascript File behind the html

async created: function () 
{
    window.parent.Xrm.Page.data.entity.addOnSave(async () => { await saveData(this) });
}
    

saveData : function()
{
    let results = await window.parent.Xrm.WebApi.online.executeMultiple(modifiedrecords);

    for (let resultsub in results) 
    {
        const result = results[resultsub];

        if (result.ok) {}
    }
}

Any help would be appreciated.


Solution

  • You are accessing the web resource's parent form using the window.parent.Xrm.Page construct. This indeed works, but it is not supported and not reliable. (Besides, in Dynamics CRM 2016 accessing the parent page is not possible anymore.)

    Entity forms are pretty complex objects that need some heavy processing before the form onload can be called. Contrary, HTML web resources that are integrated on entity forms in iFrames are often lightweight and therefore load quickly. As a result your web resource attaches itself to the onSave handler before the form is able to do that. But, this may vary, depending on the caching behaviour of the browser and other factors. Anyway, when the web resource attaches itself before the form, it is not affected by the preventDefault() down the event pipeline.

    You can solve this by giving the onLoad function on the entity form the initiative to load and/or initialize the web resource.