Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crm 2011 currency fields doesn't change currency symbol

I am facing with interesting task: in crm 2011 I have an invoice form in which placed subgrid with Invoice Line items. Invoice Line entity form contains currency fields and currency lookup and the problem is that all fields which related to currency in Invoice Line displayed with US Dollar sign '$' but all them need to display sign according to the value selected in 'Document Currency' field of an Invoice.

It can be GB pounds and when I create Invoice Line entity form it currency lookup displayed as GB pounds, but currency fields still displayed with US Dollar sign '$' . And only when user change it to null and back to GB pounds them changes.

I send Invoice document currency value's id and name as parameters ( p_DocumentCurrencyId, p_DocumentCurrencyName) to invoice line entity form and fill currency lookup on it as foloving:

Xrm.Page.getAttribute("transactioncurrencyid").setValue([{ id:   parameters["p_DocumentCurrencyId"], name: parameters["p_DocumentCurrencyName"], entityType:    "transactioncurrency"}]);

Please help!

like image 998
Ihor Sharapov Avatar asked Nov 02 '22 18:11

Ihor Sharapov


1 Answers

Okay, I have found solution by myself, here it is. We need to retrieve currency id from the lookup currency field and pass it in function thet will return currency object by id, for example function from SDK:

function retrieveCurrency(CurrencyId) {
SDK.REST.retrieveRecord(
 CurrencyId,
 "TransactionCurrency",
 null,null,
 function (currency) {
  ChangeCurrencySymbol(currency);
 },
 errorHandler
 );
}

from MS SDK http://msdn.microsoft.com/en-us/library/gg334427.aspx

And the function that will be called from successful callback and do the replacement of characters:

function ChangeCurrencySymbol(currencyInfo) {
if (currencyInfo != null) {
    var currencySymbol = currencyInfo.CurrencySymbol;
    // Looping through all currency controls on the form and sets the currency symbol.
    $.each($("span.ms-crm-Money-CurrencySymbol"), function()
    {
        this.textContent = currencySymbol;
    });        
}
}

After my research, I found that this is the only way to dynamically change currency symbols after adding value to currency lookup by javascript to date.

like image 150
Ihor Sharapov Avatar answered Nov 09 '22 05:11

Ihor Sharapov