Monday, December 12, 2016

Tricky lost focus event call in supported way dynamics crm

I had an issue where I need to access CRM text field value on command click. Everything works perfectly well if user clicks on the form after text input (on change event is being called in this case). However things does not work when user hit the command button directly.

I found a solution that perfectly works well in my case. I have done three things

A. I have created a global variable in javascript to hold the state of object when the command button gets clicked.

B. On click of command button I have updated state in global variable and call Xrm.Page.data.save() method.

C. Create a javascript function and call it on form's save event. On save check who has initated the save click i.e. command button or by some other source.


Complete Code- 

var IsCommandClicked= false;

function onSave(context) {
    if (IsCommandClicked== true) {
        IsCommandClicked= false;
        var saveEvent = context.getEventArgs();
        saveEvent.preventDefault();
    }
}

function Command  Click() {
    IsCommandClicked= true;
    Xrm.Page.data.save();
}

No comments:

Post a Comment