mercredi 6 juillet 2016

Attribute value gets cleared after being set by custom script

I'm getting this weird behaviour when updating an attribute after another one has been changed. The value in new_manual_invoice_number is somehow cleared:

function handleInvoiceNumber(context) {

        debugger;

        if (Xrm.Page.getAttribute('invoicenumber').getValue() !== undefined) {
            if (Xrm.Page.getAttribute('new_manual_invoice_number').getValue() !== undefined) {
                var manualNumber = Xrm.Page.getAttribute('invoicenumber').getValue();
                manualNumber = manualNumber.split('-')[0] + '-' + manualNumber.split('-')[1];
                Xrm.Page.getAttribute('new_manual_invoice_number').setValue(manualNumber);
            }
        }

};

This is running when invoicenumber is changed (it's a read only field and changes when the invoice is saved).

This works fine, I can see the value appearing in the form, but somehow, something clears it and I'm getting -- in the text box. It's not any of my other code, there's only thing function refering to new_manual_invoice_number.

I've tried running this code from on a save handler, form load, etc. same behaviour.

I've put a breakpoint in the form load's event too to see if it was not reloading due to auto-save or something, doesn't seem to be the issue.

Any ideas ? Quite frustating...

PS: Using Microsoft CRM 2016.

EDIT: I've also added an on change event on the attribute new_manual_invoice_number and it's never triggering :O

Aucun commentaire:

Enregistrer un commentaire