04 Mar
Posted by: mitch in: Customization, Dynamics CRM
Let me state up front that I really don't know how practical this code will be, but I did it as an intellectual exercise and because I figured that the project that I am currently working on would need it at some point.
Note: If you copy the following code for use in CRM, copy it to notepad first and replace every instance of a single and double quote with the quotes that you can type in from the keyboard. My blog engine automatically converts quotes from standard to "fancy" and those fancy quotes will not be understood by JavaScript and give you a page error.
The idea for this code is to just cycle through each table cell it finds of a specific style type and remove any currency symbol it finds.
Insert the following into the Form OnLoad event.
/* Specify the currency symbol for your part of the world*/
var sCurrencySymbol = "($)";
/*
CRM tab IDs are numbered tabx - taby, from 0 to the number of tabs-1.
For each tab that you would like to alter, insert its ID into the array
myarray.
For example, if you only wanted to alter the field labels on the General Tab
your code would be:
var myarray = new Array('tab0');
*/
var myarray = new Array('tab0', 'tab1');
for (var loop in myarray)
{
/* get a hande to the tab containing our form fields */
var tabs = document.getElementById(myarray[loop]);
/* locate all of the HTML Table structures on the Tab */
var tables = tabs.getElementsByTagName("table");
/* loop through all of the Tables on the Tab */
for (var i = 0; i < tables.length ; i++)
{
/* Locate all of the table Cells within the specified Table */
var td1 = tables[i].getElementsByTagName("TD");
/* loop through all of the Cells in the Table */
for (var i2 = 0; i2 < td1.length ; i2++)
{
var sElem = td1[i2];
/* So we're looking for Cells that have a Class of n (for number)
If we find that class, we look to see if the text within the Cell
contains our currency symbol. If it does, we delete it by replacing
it with a blank string.
*/
if ((sElem.getAttribute('className') == "n") &&
(sElem.innerHTML.indexOf(sCurrencySymbol) > 0))
sElem.innerHTML = sElem.innerHTML.replace(sCurrencySymbol, "");
}
}
}
2 Responses
Mitch Milam’s Microsoft Discussions » Blog Archive » Test post #2 with Windows Live Writer
06|Sep|2006 1[...] Let's try that code syntax plug-in again, but this time, let's use some JavaScript code from an article published back at the Spring: [...]
esh
17|Sep|2007 2If a cell is recommended or required, it will have a classname of rec or req, respectively.
Try the following set of if statements:
if ((sElem.getAttribute('className') == "n") &&
(sElem.innerHTML.indexOf(sCurrencySymbol) > 0))
sElem.innerHTML = sElem.innerHTML.replace(sCurrencySymbol, "");
else if ((sElem.getAttribute('className') == "rec") &&
(sElem.innerHTML.indexOf(sCurrencySymbol) > 0))
sElem.innerHTML = sElem.innerHTML.replace(sCurrencySymbol, "");
else if ((sElem.getAttribute('className') == "req") &&
(sElem.innerHTML.indexOf(sCurrencySymbol) > 0))
sElem.innerHTML = sElem.innerHTML.replace(sCurrencySymbol, "");
Leave a reply