5
votes

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!

1
Are you using the native invoice & invoicedetail entities or custom entities?Andy Meyers
@AndyMeyers: Invoice entity is native and Invoice line is custom.Ihor

1 Answers

2
votes

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.