Answered by:
JavaScript to Hide/Show attribute based on the lookup value

Question
-
Hi Everyone,
I need a little help here....
I have a form named "Company". There's a lookup on that form "Division". What I want is that whenever I click on "Division lookup" and if I select a value say "ABC" than a field name "Sub" needs to be hidden.
Note:
Want to hide field "Sub" on the basis of the selection of a value from a lookup "Division".
Wednesday, October 10, 2012 10:16 AM
Answers
-
Hi,
you can use something like this:
function onCompanyLoad(){ Xrm.Page.getAttribute("yourLookupSchemaName").addOnChange(onMyLookupChange); } function onMyLookupChange(){ var lookupField = new Array(); lookupField = Xrm.Page.getAttribute("yourLookupSchemaName").getValue(); if (lookupField != null) { var name = lookupField[0].name; var guid = lookupField[0].id; if (name == "yourvalue"){ Xrm.Page.getControl("subFieldSchemaName").setVisible(false); } } }
You can add the "onCompanyLoad" function to the OnLoad event of your form.
Greetings,
Pavlos
Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
- Proposed as answer by Mayank Pujara Wednesday, October 10, 2012 10:41 AM
- Marked as answer by Umes Kumar Wednesday, October 10, 2012 10:42 AM
Wednesday, October 10, 2012 10:27 AM -
My Friend,
Check for http://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_setVisible ( you can download latest SDK if you have not done yet)
you can simple check for the value like below
if(Xrm.Page.getAttribute(“Nameof ID field”).getValue()!=null)
{
var Name = Xrm.Page.getAttribute(“Nameof ID field”).getValue()[0].name;
if(Name=="Value")
{
//code to hide control
var control = Xrm.Page.ui.controls.get("Field");
control.setVisible(false);
}
}Contact Me
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Proposed as answer by Mayank Pujara Wednesday, October 10, 2012 10:41 AM
- Marked as answer by Umes Kumar Wednesday, October 10, 2012 10:44 AM
Wednesday, October 10, 2012 10:32 AMModerator
All replies
-
Hi,
you can use something like this:
function onCompanyLoad(){ Xrm.Page.getAttribute("yourLookupSchemaName").addOnChange(onMyLookupChange); } function onMyLookupChange(){ var lookupField = new Array(); lookupField = Xrm.Page.getAttribute("yourLookupSchemaName").getValue(); if (lookupField != null) { var name = lookupField[0].name; var guid = lookupField[0].id; if (name == "yourvalue"){ Xrm.Page.getControl("subFieldSchemaName").setVisible(false); } } }
You can add the "onCompanyLoad" function to the OnLoad event of your form.
Greetings,
Pavlos
Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
- Proposed as answer by Mayank Pujara Wednesday, October 10, 2012 10:41 AM
- Marked as answer by Umes Kumar Wednesday, October 10, 2012 10:42 AM
Wednesday, October 10, 2012 10:27 AM -
My Friend,
Check for http://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_setVisible ( you can download latest SDK if you have not done yet)
you can simple check for the value like below
if(Xrm.Page.getAttribute(“Nameof ID field”).getValue()!=null)
{
var Name = Xrm.Page.getAttribute(“Nameof ID field”).getValue()[0].name;
if(Name=="Value")
{
//code to hide control
var control = Xrm.Page.ui.controls.get("Field");
control.setVisible(false);
}
}Contact Me
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Proposed as answer by Mayank Pujara Wednesday, October 10, 2012 10:41 AM
- Marked as answer by Umes Kumar Wednesday, October 10, 2012 10:44 AM
Wednesday, October 10, 2012 10:32 AMModerator -
Hi,
can you show us the code you have written so far?
Greetings,
Pavlos
Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
Wednesday, October 10, 2012 11:00 AM -
Use it like below
if(Xrm.Page.getAttribute(“Nameof ID field”).getValue()!=null)
{
var Name = Xrm.Page.getAttribute(“Nameof ID field”).getValue()[0].name;var control = Xrm.Page.ui.controls.get("Field");
if(Name=="Value")
{
//code to show control
control.setVisible(true);
}
else //else hide
control.setVisible(false);
}
Contact Me
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.Wednesday, October 10, 2012 11:01 AMModerator