Asked by:
Show/Hide Field based on a Lookup field.

Question
-
I am using CRM2011 trying to hide a Lookup field (SubPracticeArea) until another Lookup field(PrimaryPracticeArea) is populated. Below is my script
function DisableSubPracticeAreaLookup() {
var PrimaryPracticeArea = Xrm.Page.data.entity.attributes.get("cpdc_primarypracticearea").getValue();
if (PrimaryPracticeArea == false) {
Xrm.Page.ui.controls.get("cpdc_subpracticearea").setVisible(false);
}
else {
Xrm.Page.ui.controls.get("cpdc_subpracticearea").setVisible(true);
}
}I keep getting an error that 'Onload' is undefined.....how can I fix this?
Monday, March 30, 2015 8:08 PM
All replies
-
you usually get that error when there is script errors. Is this the only script?. Check if you have forgotten a closing }.
Monday, March 30, 2015 10:21 PM -
also it may be more appropriate to check for null.
PrimaryPracticeArea == false
PrimaryPracticeArea == null
Monday, March 30, 2015 10:22 PM -
Jithesh is correct, check for null rather than false. I think there are some more scripts running on the page that could be causing error.
Jugal Kishore Dandamudi.
Tuesday, March 31, 2015 5:59 AM -
Hi,
I think you need to check for null rather than false.
Wednesday, April 1, 2015 7:49 AM -
Hi,
which function name is set in field/form event?
Sounds like the function name "Onload" is set in event properties but does not exists in your jscript code.
Rob
Wednesday, April 1, 2015 8:01 AM -
Change your code like below
if(Xrm.Page.data.entity.attributes.get("cpdc_primarypracticearea")!=null && Xrm.Page.data.entity.attributes.get("cpdc_primarypracticearea").getValue()==null)
{
Xrm.Page.ui.controls.get("cpdc_subpracticearea").setVisible(false);
}
else {
Xrm.Page.ui.controls.get("cpdc_subpracticearea").setVisible(true);
}
}Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Wednesday, April 1, 2015 10:27 AMModerator