MS Dynamics CRM 4.0 - onChange event error

1.9k Views Asked by At

I have an onChange event that keeps bringing up the error below whenever I preview it.

'Object doesnt support this property or method'

I have the onChange event associated with a picklist and when a specific option is selected another field is unhidden.

The code is below:

onLoad:

//If How did you hear about us is set to event show the Source Event lookup
crmForm.SourceEvent = function SourceEvent() 
{
if (crmForm.all.gcs_howdidyouhearaboutus.DataValue == 5)
{
crmForm.all.gcs_sourceeventid_c.style.display = '' ;
crmForm.all.gcs_sourceeventid_d.style.display = '' ;
}
else
{
crmForm.all.gcs_sourceeventid_c.style.display = 'none' ;
crmForm.all.gcs_sourceeventid_d.style.display = 'none' ;
}
}
crmForm.SourceEvent() ;

onChange

crmForm.SourceEvent() ;

Would be great if someone could let me know why this error is showing up?

Also, this has happened on a few onChange events on the form preview but once published onto the live system it does not error. Any ideas?

Thank you

Brett

2

There are 2 best solutions below

0
On BEST ANSWER

Overriding SourceEvent is not the supported way of doing that...

You should probably use the fire the OnChange event in the form load using (if (crmForm.all.yourLookup) { crmForm.all.yourLookup.FireOnChange();} and in the field's javascript onChange event write something like

var displayStyle = (crmForm.all.cf_picklist.DataValue == "3") ? "none" : "";
crmForm.all.cf_lookupid_d.style.display = displayStyle;
crmForm.all.cf_lookupid_c.style.display = displayStyle;

note that changing the Display CSS element is not supported, but it's the only way of doing that, without writing your own ASPX page.

ref: http://www.eggheadcafe.com/software/aspnet/31267662/hide-lookup-based-on-pick.aspx

1
On

It probably means that either form elements with the "id" values you expect don't actually exist, or that you've used an "id" value more than once.

Also: that way of accessing elements will only work in IE. Maybe that's what you want, but you can make it work in other browsers by using document.getElementById()