Reputation: 457
I have javascript on my form wherein onchange of a field, currency is set.
For eg i have a field named 'Field1', on change of a value in 'Field1', currency is set and an another money field (say price) is set based on the currency selected.
So the scenario is, when the value from Field1 is removed, currency and price both are set to blank,after then if a value is selected in Field1, eventhough the currency is set it throws an error "Currency is required if a value exists". My Assumption is it throws the error because i am trying to set the price field also after setting the currency.
Below is the code used to set currency.
var arrLookupData = new Array();
var objLookupItem = new Object();
objLookupItem.typename = "transactioncurrency";
objLookupItem.id = varray.id;
objLookupItem.name = varray.name;
arrLookupData[0] = objLookupItem;
Xrm.Page.getAttribute("transactioncurrencyid").setValue(arrLookupData);
Xrm.Page.getAttribute("transactioncurrencyid").fireOnChange();
//Some code
Xrm.Page.getAttribute("core_price").setValue(value);
Kindly suggest.
Upvotes: 0
Views: 170
Reputation: 23300
Make sure you invoke fireOnChange
after you set values in fields from Javascript, otherwise the form won't "see" the new data.
Your code would become:
var arrLookupData = new Array();
//
// omitted
//
Xrm.Page.getAttribute("transactioncurrencyid").setValue(arrLookupData);
Xrm.Page.getAttribute("transactioncurrencyid").fireOnChange();
Upvotes: 1