Recently we had a scneario wherein the currency field on the opportunity was to be set dynamically with the currency of the associated contact/account.
This currency is automatically set to the currency of the account/contact if the opportunity has been opened from within an account/contact, however it does not reflect the associated currency when the customer is changed.
So had to make an ajax call on the onchange event of the customer field to retrieve its associated currency and set it on the opportunity entity.
However this does not change the currency symbol values on the money fields on the form.
There seems to be an internal script being fired to update the currency symbols whenever the currency is changed.
The same is not fired when the currency value is populated via javascript.
Below is the javascript which can be used to update the symbols whenever the currency is set dynamically:
//loops thru all controls on the form and sets the currency symbol
var oCtrl;
for (var i = 0; i < crmForm.all.length; i++)
{
oCtrl = crmForm.all[i];
if(oCtrl.tagName == "INPUT" && oCtrl.className == "ms-crm-Money-CurrencySymbol")
{
//currencySymbol contains the actual symbol
oCtrl.value = currencySymbol;
}
}
I found your entry and has made some improvements to it and refer to you:
ReplyDeletehttps://markuserlandsson.wordpress.com/2011/02/28/change-currency-on-form-with-javascript/