I am converting the Potential Account Size field to in Lead Tab - Web InfoTab to a combo box using jscript in the OnLoad event. This code worked just fine in the Salutation field in Lead Tab-General Tab but refuses to work in
this field and I am relatively new to jscript. This development is in CRM 3.0. Can someone give me a clue to what is wrong? Here is the code:
//DROP DOWN BOX FOR POTENTIAL ACCOUNT SIZE
//The potential account size lookup field to change.
var fieldN = "new_potentialaccountsize";
//I'm saving the current potential account size value to set it as
the
default in the created combobox.
var defaultV = crmForm.all.item(fieldN).DataValue;
//This is the TD element containing the text box control. We will
replace
the entire innerHTML to replace
//the input type="text" element with a select element.
var tble = crmForm.all.item(fieldN + "_d");
//This is the beginning of our new combobox. It's a standard HTML
declaration and all we need to do is to
//fill the appropriate options. You should check the original HTML
code to
get the appropriate values for
//req (field required level) and the tab index.
var selection = "<selection req='0' id='" + fieldN + "' name='" +
fieldN +
"' defaultSelected='' class='selectBox' tabindex='1380'>";
//The defaultValFd serves as an indicator if the current field value
(defaultV) corresponds to one
//of the options we have inserted into the combobox. If the current
value
was not found, we will insert it as
//a separate option, ensuring that the stored value always is
displayed.
var defaultValFd = false;
//This is the potential account size list. Empty string is added as
the
first array element, allowing a user to remove a selection.
var Optns = new Array(
"",
"Ms.",
"Mr.",
"Mrs.",
"Doctor",
"Miss"
);
//Now let's add all of the potential account size names as option
elements.
for (index in Optns) {
//Create a new option element and set the value to the current
potential
account size of the loop. The value provided in
//the value attribute will be stored in the database, so you have
the
option to use ISO codes or numbers
//if you want. As I always want to have the full potential account
size
name stored in the database, I use the full
//potential account size name.
selection += "<Optns value='" + Optns[index] + "'";
//If this is the default value (the current value stored in the
entity),
I do two things: first, I add the
//SELECTED attribute to the current option, forcing the combobox
to
select it by default. Second, I set
//defaultValFd to true, indicating that I don't need to add the
default
value to the list after
//exiting this loop.
if (Optns[index] == defaultV) {
selection += " SELECTED";
defaultValFd = true;
}
//Add the remaining parts of the Optns element. The value
specified
between <Optns> and </Optns> is
//the text displayed in the combobox. In this sample it's identical
to
the text provided in the value
//attribute.
selection += ">" + Optns[index] + "</Optns>";
}
//Here's the part that ensures that an existing entity will always
display
the stored value of the
//potential account size field, no matter if it is included in the
option
list or not. If it is set and it was not found
//in the previous loop, then defaultValFd will still be false and we
have to
add it as a separate
//option, which is also SELECTED.
if ((defaultV != null) && (defaultV.length > 0) && !defaultValFd) {
selection += "<Optns value='" + defaultV + "' SELECTED>" + defaultV
+
"</Optns>";
}
//Close the open select element.
selection += "</selection>";
//Finally, I replace the entire definition of the text box with the
newly
constructed combobox. IE is very
//smart and will instantly update the window. You now have a combobox
with a
list of all
//potential account size and it will be saved directly to the
potential
account size field.
tble.innerHTML = selection;
Thanks for all help in advance.
Dave C.
this field and I am relatively new to jscript. This development is in CRM 3.0. Can someone give me a clue to what is wrong? Here is the code:
//DROP DOWN BOX FOR POTENTIAL ACCOUNT SIZE
//The potential account size lookup field to change.
var fieldN = "new_potentialaccountsize";
//I'm saving the current potential account size value to set it as
the
default in the created combobox.
var defaultV = crmForm.all.item(fieldN).DataValue;
//This is the TD element containing the text box control. We will
replace
the entire innerHTML to replace
//the input type="text" element with a select element.
var tble = crmForm.all.item(fieldN + "_d");
//This is the beginning of our new combobox. It's a standard HTML
declaration and all we need to do is to
//fill the appropriate options. You should check the original HTML
code to
get the appropriate values for
//req (field required level) and the tab index.
var selection = "<selection req='0' id='" + fieldN + "' name='" +
fieldN +
"' defaultSelected='' class='selectBox' tabindex='1380'>";
//The defaultValFd serves as an indicator if the current field value
(defaultV) corresponds to one
//of the options we have inserted into the combobox. If the current
value
was not found, we will insert it as
//a separate option, ensuring that the stored value always is
displayed.
var defaultValFd = false;
//This is the potential account size list. Empty string is added as
the
first array element, allowing a user to remove a selection.
var Optns = new Array(
"",
"Ms.",
"Mr.",
"Mrs.",
"Doctor",
"Miss"
);
//Now let's add all of the potential account size names as option
elements.
for (index in Optns) {
//Create a new option element and set the value to the current
potential
account size of the loop. The value provided in
//the value attribute will be stored in the database, so you have
the
option to use ISO codes or numbers
//if you want. As I always want to have the full potential account
size
name stored in the database, I use the full
//potential account size name.
selection += "<Optns value='" + Optns[index] + "'";
//If this is the default value (the current value stored in the
entity),
I do two things: first, I add the
//SELECTED attribute to the current option, forcing the combobox
to
select it by default. Second, I set
//defaultValFd to true, indicating that I don't need to add the
default
value to the list after
//exiting this loop.
if (Optns[index] == defaultV) {
selection += " SELECTED";
defaultValFd = true;
}
//Add the remaining parts of the Optns element. The value
specified
between <Optns> and </Optns> is
//the text displayed in the combobox. In this sample it's identical
to
the text provided in the value
//attribute.
selection += ">" + Optns[index] + "</Optns>";
}
//Here's the part that ensures that an existing entity will always
display
the stored value of the
//potential account size field, no matter if it is included in the
option
list or not. If it is set and it was not found
//in the previous loop, then defaultValFd will still be false and we
have to
add it as a separate
//option, which is also SELECTED.
if ((defaultV != null) && (defaultV.length > 0) && !defaultValFd) {
selection += "<Optns value='" + defaultV + "' SELECTED>" + defaultV
+
"</Optns>";
}
//Close the open select element.
selection += "</selection>";
//Finally, I replace the entire definition of the text box with the
newly
constructed combobox. IE is very
//smart and will instantly update the window. You now have a combobox
with a
list of all
//potential account size and it will be saved directly to the
potential
account size field.
tble.innerHTML = selection;
Thanks for all help in advance.
Dave C.