Get Currency symbol based on currency ID


Today I saw one post in MS CRM development forum, where user needs to get currency symbol based on currency id, so thought to write this post to help. you can use below code to get currency symbol based on currency id

function GetCurrencySymbol() {

if(Xrm.Page.getAttribute(“transactioncurrencyid”).getValue()!=null)
{
    var CurrencyID = Xrm.Page.getAttribute(“transactioncurrencyid”).getValue()[0].id;
    var context = Xrm.Page.context;
    var serverUrl = context.getServerUrl();
    var ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;
    var retrieveCurrency= new XMLHttpRequest();
    retrieveCurrency.open(“GET”, ODataPath + “/TransactionCurrencySet(guid'” + CurrencyID+ “‘)”, false);
    retrieveCurrency.setRequestHeader(“Accept”, “application/json”);
    retrieveCurrency.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
    retrieveCurrency.onreadystatechange = function() {
        retrieveCurrencyCallBack(this);
    };
    retrieveCurrency.send();
    }

}
function retrieveCurrencyCallBack(retrieveCurrency) {
    if (retrieveCurrency.readyState == 4 /* complete */) {
        if (retrieveCurrency.status == 200) {

            var retrievedParent = this.parent.JSON.parse(retrieveCurrency.responseText).d;

                    alert(retrievedParent.CurrencySymbol);

}
 
}}

 Enjoy !!!

Advertisements

Leave a comment

Filed under MS CRM 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s