javascript - Change symbols of currency fields upon changing Currency on the Form in CRM 2011 -


some of might have faced issue in microsoft dynamics crm 2011 today when assigned task change currency lookup value dynamically match account currency in case of difference. did same calling setlookupvalue javascript function set currency value according account currency.

setlookupvalue("transactioncurrencyid", "transactioncurrency", accountcurrency.id, accountcurrency.name); 

after doing unit test, currency lookup value changing observed currency symbols of fields defined currency datatype on form not changing destination currency in case accountcurrency.

e.g. currency field changed us dollar (usd) euro (eur) fields showing usd prefix.

after spending hours on web gathered useful information in chunks different sources respect problem.

i have managed device 2 ways , tested both ways on ie browser microsoft dynamics crm 2011 change currency symbol of every currency field on form dynamically.


  • using odata (simple , effective no cross-browser compatibility issue):
function changecurrencysymbolodata(guid) {     returnvalue = retrievemultiple("transactioncurrencyset", "?$filter=transactioncurrencyid eq guid'" + guid + "'");     if (returnvalue != null && returnvalue[0] != null) {         var currencyinfo = returnvalue[0];         // looping through controls on form , sets currency symbol.         var octrl;         (var = 0; < crmform.all.length; i++) {             octrl = crmform.all[i];             if (octrl.tagname == "input" &&                         (octrl.classname == "ms-crm-money-currencysymbol" ||                         octrl.classname == "ms-crm-money-currencysymbol ms-crm-readonly")) {                 octrl.value = currencyinfo.isocurrencycode;             }         }     } } 

usage:

changecurrencysymbolodata(accountcurrency.id); 

where accountcurrency referring euro (eur) currency.


  • using fetch xml
function changecurrencysymbolfetchxml(isocurrencycode) {     var currencysymbolname = crmform.all.transactioncurrencyid.cursymclm;     // ensuring currency present.     var fetchcurr = '<fetch mapping="logical" count="50" version="1.0">';     fetchcurr += '<entity name="transactioncurrency">';     fetchcurr += '  <attribute name="currencyname" />';     fetchcurr += '  <attribute name="' + currencysymbolname + '" />';     fetchcurr += '    <filter>';     fetchcurr += '        <condition attribute="isocurrencycode" operator="eq" value="' + isocurrencycode + '" />';     fetchcurr += '    </filter>';     fetchcurr += '</entity>';     fetchcurr += '</fetch>';      results = dofetch(fetchcurr);     if (results != null && results.length > 0) {         var currency = results[0].selectsinglenode('./transactioncurrencyid');         // checking if same currency selected, there no need change anything.         if (crmform.all.transactioncurrencyid.datavalue == null ||             crmform.all.transactioncurrencyid.datavalue[0].id != currency.text) {             var currencyname = results[0].selectsinglenode('./currencyname').text;             // defining variable hold actual symbol.             var currencysymbol = results[0].selectsinglenode('./' + currencysymbolname).text;             var lookupdata = new array();             var lookupitem = new object();             // setting id, typename, , name properties object.             lookupitem.id = currency.text;             lookupitem.name = currencyname;             lookupitem.typename = 'transactioncurrency';              // adding object array.             lookupdata[0] = lookupitem;             // setting value of lookup field value of array.             crmform.all.transactioncurrencyid.datavalue = lookupdata;             crmform.all.transactioncurrencyid.forcesubmit = true;              // looping through controls on form , sets currency symbol.             var octrl;             (var = 0; < crmform.all.length; i++) {                 octrl = crmform.all[i];                 if (octrl.tagname == "input" &&                     (octrl.classname == "ms-crm-money-currencysymbol" ||                     octrl.classname == "ms-crm-money-currencysymbol ms-crm-readonly")) {                     octrl.value = currencysymbol;                 }             }         }     } }  function dofetch(fetchxml) {     fetchxml = fetchxml.replace(/</g, '&lt;');     fetchxml = fetchxml.replace(/>/g, '&gt;');     // preparing soap message.     var xml = "<?xml version='1.0' encoding='utf-8'?>"     xml += "<soap:envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' "     xml += "xmlns:xsi='http://www.w3.org/2001/xmlschema-instance' "     xml += "xmlns:xsd='http://www.w3.org/2001/xmlschema'>";     xml += xrm.page.context.getauthenticationheader();     xml += "<soap:body>";     xml += "<fetch xmlns='http://schemas.microsoft.com/crm/2007/webservices'><fetchxml>";     xml += fetchxml;     xml += "</fetchxml></fetch>";     xml += "</soap:body></soap:envelope>";      // preparing xmlhttpobject , send request.     var xhreq = new activexobject("msxml2.xmlhttp");     xhreq.open("post", "/mscrmservices/2007/crmservice.asmx", false);     xhreq.setrequestheader("soapaction", "http://schemas.microsoft.com/crm/2007/webservices/fetch");     xhreq.setrequestheader("content-type", "text/xml; charset=utf-8");     xhreq.setrequestheader("content-length", xml.length);     xhreq.send(xml);      // capturing result.     var resultxml = xhreq.responsexml;      // checking errors.     var errorcount = resultxml.selectnodes('//error').length;     if (errorcount != 0) {         var msg = resultxml.selectsinglenode('//description').nodetypedvalue;         alert(msg);     }     // process , display results.     else {         // capturing result , unencode it.         var resultset = new string();         resultset = resultxml.text;         resultset.replace('&lt;', '<');         resultset.replace('&gt;', '>');          // creating xml document can parse.         var oxmldoc = new activexobject("microsoft.xmldom");         oxmldoc.async = false;          // loading xml document has unencoded results.         oxmldoc.loadxml(resultset);          // displaying results.         var results = oxmldoc.getelementsbytagname('result');         return results;     } } 

usage:

changecurrencysymbolfetchxml('eur'); 

resources:


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -