Answered by:
Javascript after Upgrading to CRM 4.0

Question
-
Hi,
Just wondering if anybody knows why when I run an upgrade from CRM 3.0 to CRM 4.0 javascripts I have written to hide fields based on user selection through out an record doesn't work. Currently all the fields are visable and enabled.
They work fine in CRM 3.0 but not when I upgrade.
Thanks,
Matthew.Friday, February 8, 2008 6:04 AM
Answers
-
Hi.
You can use these utility functions to Show/Hide or Disable/Enable Controls.
Code Snippetfunction OnCrmPageLoad()
{
//Show / Hide
//DisplayControl( "new_carootid" , DisplayType.None );
//DisplayControl( "new_customertype" , DisplayType.None );
// Disable / Enable
//DisableControl( "new_lastname" , true );
//DisableControl( "new_customertype" , true );
//DisableControl( "new_carootid" , true );
}
var DisplayType = { None : "None" , Inline : "Inline" }
function DisplayControl( controlId , displayType )
{
var getElement = document.getElementById;
//Control Container (TD)
var control_d = getElement( controlId + "_d" );
if( control_d )
control_d.style.display = displayType;
//Control Label
var control_c = getElement( controlId + "_c" );
if( control_c )
control_c.style.display = displayType;
var control = getElement( control );
if( control )
control.style.display = displayType;
}
function DisableControl( controlId , disabled )
{
var control = document.getElementById( controlId );
if( control )
control.Disabled = disabled;
}
OnCrmPageLoad();
This should work in both CRM 3.0 and 4.0.
Cheers,
Adi
Monday, February 11, 2008 4:32 PM
All replies
-
Dear Mattew,
see my post on http://microsoftcrm3.blogspot.com
Thursday, January 31, 2008
You have to update your web services in javascript after upgrade.
Best Regards,
Imran
http://microsoftcrm3.blogspot.com
Friday, February 8, 2008 7:27 AMModerator -
Can you post the code; it depends how you were hiding the fields.
Be aware that there was no supported way to hide fields in CRM 3.0, so there was no guarantee the cod ewould still work
Friday, February 8, 2008 7:42 AMModerator -
David,
This is a sample from the code that I have which shows some fields being hidden and displayed.
Code Snippet//hiding Relocation Section
crmForm.all.edv_existingaddress.parentElement.parentElement.parentElement.style.display =
'none'; //hiding Business Broadband and Bigpond OptionscrmForm.all.edv_bbtidworkrequired.parentElement.parentElement.parentElement.style.display =
'none';crmForm.all.edv_bbtidstarterallowance.parentElement.parentElement.parentElement.style.display =
'none';crmForm.all.edv_bbtidadvantagespeed.parentElement.parentElement.parentElement.style.display =
'none';crmForm.all.edv_bbtidbigacctno.parentElement.parentElement.parentElement.style.display =
'none';crmForm.all.edv_existingaddress.parentElement.parentElement.parentElement.style.display =
'none'; //hiding all Winback optionscrmForm.all.edv_winbackqtysvc.parentElement.parentElement.parentElement.style.display =
'none';crmForm.all.edv_winbackopt1.parentElement.parentElement.parentElement.style.display =
'none';crmForm.edv_winbacksvcno1.parentElement.parentElement.parentElement.style.display =
'none'; //hiding Single Bill SectioncrmForm.all.edv_pstnservicestomodify.parentElement.parentElement.parentElement.style.display =
'none';// End of hiding Service Sections
/* This section will disable all manditory fields that are based on other selections. This section does not
disable manditory fields that must be filled in for all orders. */
//PSTNcrmForm.all.edv_inplacenumber.Disabled =
truecrmForm.all.edv_pstnworkrequired.Disabled =
truecrmForm.all.edv_pstnserviceqty.Disabled =
true //ISDN2crmForm.all.edv_isdn2serviceqty.Disabled =
truecrmForm.all.edv_isdn2workrequired.Disabled =
truecrmForm.all.edv_isdn2product.Disabled =
truecrmForm.all.edv_isdn2indialpreference.Disabled =
truecrmForm.all.edv_isdn2numberrange.Disabled =
true //ISDN30crmForm.all.edv_isdn30workrequired.Disabled =
truecrmForm.all.edv_isdn30serviceqty.Disabled =
truecrmForm.all.edv_isdn30channels.Disabled =
truecrmForm.all.edv_isdn30indialpreference.Disabled =
truecrmForm.all.edv_isdn30norangepref.Disabled =
true //Relocation RequirementscrmForm.all.edv_existingaddress.Disabled =
true //Business BroadbandcrmForm.all.edv_bbtidadvantagedownload.Disabled =
truecrmForm.all.edv_bbtidadvantagespeed.Disabled =
truecrmForm.all.edv_bbtidbdslallow.Disabled =
truecrmForm.all.edv_bbtidbigacctno.Disabled =
truecrmForm.all.edv_bbtidbigpondadslfnn.Disabled =
truecrmForm.all.edv_bbtidbigpondusername.Disabled =
truecrmForm.all.edv_bbtidcontractterm.Disabled =
truecrmForm.all.edv_bbtidexistacctno.Disabled =
truecrmForm.all.edv_bbtidexistingfnn.Disabled =
truecrmForm.all.edv_bbtidinstallationtype.Disabled =
truecrmForm.all.edv_bbtidplantype.Disabled =
truecrmForm.all.edv_bbtidsiteaddress.Disabled =
truecrmForm.all.edv_bbtidstarterallowance.Disabled =
truecrmForm.all.edv_bbtidstarterspeed.Disabled =
truecrmForm.all.edv_bbtidworkrequired.Disabled =
true //WinbackcrmForm.all.edv_winbackqtysvc.Disabled =
truecrmForm.all.edv_winbackcallingplan.Disabled =
truecrmForm.all.edv_winbackexistsupp.Disabled =
truecrmForm.all.edv_winbackcurrentacct.Disabled =
truecrmForm.all.edv_winbackexistacct.Disabled =
truecrmForm.all.edv_winbacktlscharge.Disabled =
truecrmForm.all.edv_winbackopt1.Disabled =
truecrmForm.all.edv_winbackopt2.Disabled =
truecrmForm.all.edv_winbackopt3.Disabled =
true //Winback Service NumberscrmForm.all.edv_winbacksvcno1.Disabled =
truecrmForm.all.edv_winbacksvcno2.Disabled =
truecrmForm.all.edv_winbacksvcno3.Disabled =
truecrmForm.all.edv_winbacksvcno4.Disabled =
truecrmForm.all.edv_winbacksvcno5.Disabled =
truecrmForm.all.edv_winbacksvcno6.Disabled =
truecrmForm.all.edv_winbacksvcno7.Disabled =
truecrmForm.all.edv_winbacksvcno8.Disabled =
true// End Manitory Fields
// This will allow user to select related project if the related entity box is ticked. if(crmForm.all.edv_requiredforproject.DataValue == true){
crmForm.all.edv_relatedprojectid.Disabled =
false;crmForm.all.edv_relatedprojectid.src =
'/_imgs/btn_on_lookup.gif';}
else{
crmForm.all.edv_relatedprojectid.disable =
true;crmForm.all.edv_relatedprojectid.src =
'/_imgs/btn_dis_lookup.gif';}
// This will confirm that user wishes to proceed with sending order to MAC
crmForm.all.edv_submittomac.onclick =
function(){
if(crmForm.all.edv_submittomac.checked==true){
var truthBeTold = confirm("By proceeding this order will be sent to MAC for processing"); if (truthBeTold){
crmForm.all.edv_submittomac.DataValue=
true;}
else{
crmForm.all.edv_submittomac.DataValue=
false;}
}
else{
}
}
// This will allow MAC to view Processing Checklist Tab when order submitted to MAC
// onSave this will open up the MAC Checklist once user has completed the order and sent to MAC
if(crmForm.all.edv_submittomac.checked==true){
crmForm.all.tab1Tab.style.display =
"inline";}
else{
crmForm.all.tab1Tab.style.display =
"none";}
// This section of script will reopen necessary service sections based on the Service Type selected by the user
// Display PSTN Options if(crmForm.all.edv_servicetyperequired.options[crmForm.all.edv_servicetyperequired.selectedIndex].text =="PSTN"){
crmForm.all.edv_pstnworkrequired.parentElement.parentElement.parentElement.style.display =
"inline";crmForm.all.edv_inplacenumber.parentElement.parentElement.parentElement.style.display =
"inline";crmForm.all.edv_inplacenumber.Disabled =
falsecrmForm.all.edv_pstnworkrequired.Disabled =
falsecrmForm.all.edv_pstnserviceqty.Disabled =
false}
else{
crmForm.all.edv_pstnworkrequired.parentElement.parentElement.parentElement.style.display =
"none";crmForm.all.edv_inplacenumber.parentElement.parentElement.parentElement.style.display =
"none";crmForm.all.edv_inplacenumber.Disabled =
truecrmForm.all.edv_pstnworkrequired.Disabled =
truecrmForm.all.edv_pstnserviceqty.Disabled =
true}
Saturday, February 9, 2008 4:47 AM -
Hi.
The Problem is DOM related. Microsoft changed to structure of the HTML Document Object Model.
So a statement like:
crmForm.all.edv_pstnworkrequired.parentElement.parentElement.parentElement.style.display = "none";Might not exist, witch means that one of the parentElements is null;
Use the debugger; keyword at the top of the script and see exactly where it falls.
You will need to uncheck "disable script debugging for internet explorer under tools --> internet option --> advanced tab.
Cheers
Adi
Sunday, February 10, 2008 1:22 AM -
Adi,
This would appear to be the problem. Just wondering if anybody knows what command you can use in the new version of CRM that will hide and disable fields based on other information selected.
Thanks,
Matthew.
Monday, February 11, 2008 1:09 AM -
Hi.
You can use these utility functions to Show/Hide or Disable/Enable Controls.
Code Snippetfunction OnCrmPageLoad()
{
//Show / Hide
//DisplayControl( "new_carootid" , DisplayType.None );
//DisplayControl( "new_customertype" , DisplayType.None );
// Disable / Enable
//DisableControl( "new_lastname" , true );
//DisableControl( "new_customertype" , true );
//DisableControl( "new_carootid" , true );
}
var DisplayType = { None : "None" , Inline : "Inline" }
function DisplayControl( controlId , displayType )
{
var getElement = document.getElementById;
//Control Container (TD)
var control_d = getElement( controlId + "_d" );
if( control_d )
control_d.style.display = displayType;
//Control Label
var control_c = getElement( controlId + "_c" );
if( control_c )
control_c.style.display = displayType;
var control = getElement( control );
if( control )
control.style.display = displayType;
}
function DisableControl( controlId , disabled )
{
var control = document.getElementById( controlId );
if( control )
control.Disabled = disabled;
}
OnCrmPageLoad();
This should work in both CRM 3.0 and 4.0.
Cheers,
Adi
Monday, February 11, 2008 4:32 PM -
Your code does not work....
Error: Object Expected
Wednesday, March 19, 2008 6:20 PM -
Witch line? How did you implement it?
Post your onload implementation here and I'll fix it in a sec.
Cheers,
Adi
Wednesday, March 19, 2008 6:27 PM -
Imran - mscrmexpert wrote: Dear Mattew,
see my post on http://microsoftcrm3.blogspot.com
Thursday, January 31, 2008
You have to update your web services in javascript after upgrade.
Best Regards,
Imran
http://microsoftcrm3.blogspot.com
i also want to hide some field ,but it doesn't work.
i used : crmForm.all.new_myaddress.style.display = 'none';
it doesn't work when i use Adi's code , is it the problem of "You have to update your web services in javascript after upgrade."
the first time of putting my question in english , wish somebody can understand
Thanks,
Sunday, June 8, 2008 9:17 PM