Search code examples
javascriptdynamics-crm-2011ribbon

Unable to save changes made to entity when calling javascript function through custom ribbon button event


I'm trying to create a simple function which, when ribbon button is pressed, sets entity attribute value to null. Now the problem I am facing is, that the changes I make to the entity are not saved, form reloads and returns previous value.

To the button event I pass 'Task' activity attribute 'actualend'. 'Actual End' field is disabled by default.

ClearField: function (field) {
    if (Xrm.Page.getAttribute(field) == null) return;

    Xrm.Page.ui.controls.get(field).setDisabled(false);
    Xrm.Page.getAttribute(field).setSubmitMode("always");
    Xrm.Page.getAttribute(field).setValue(null);

    if (Xrm.Page.data.entity.getIsDirty()) {
        Xrm.Page.data.entity.save(); //also tried addOnSave(function)
    }
}

Following debugger I was able to track that all changes are made correctly, except that on save() method they are 'discarded', then form reloads with previous value. This code works fine with CRM UR8 yet with CRM UR13 it does not.

Am I missing something?


Solution

  • Eh, the problem with my issue all this time was that even though the field existed in the form, it never had an entity passed to it, therefore it was unable to save it. I've edited a ribbon button so to pass entity through CrmParameters and the issue was gone. Thank you both for supplying me with possible solutions regardless!