onchange event crm2011
-
Monday, August 29, 2011 6:12 AM
hello,
i'm trying to create a dynamic field in some form entity that i created.
the thing i need is:
an on change event,
i have a drop down list that has some values in it.
i need the form to change when i'm choosing different value.
meaning if i chose 'A' in list
present fields 1 2 3
if i chose 'B' present 1 3 6
i'm new to this so hope to get a full answer...
10x a lot !
All Replies
-
Monday, August 29, 2011 7:10 AM
Hi,
Try the following code on Picklist OnChange event funtion:
if ( Xrm.Page.data.entity.attributes.get(“picklistfieldname”).getText() == "A")var field1 = Xrm.Page.ui.controls.get("field_1_name");
field1.setVisible(true);
var field2 = Xrm.Page.ui.controls.get("field_2_name");
field2.setVisible(true);
}
else if ( Xrm.Page.data.entity.attributes.get(“picklistfield”).getText() == "B")
{
var field1 = Xrm.Page.ui.controls.get("field_1_name");
field1.setVisible(true);
var field3 = Xrm.Page.ui.controls.get("field_3_name");
field3.setVisible(true);
}
Intially you can hide all fields and then on the based of values can show. Also you can add more fields to hide/show as per required.
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed As Answer by Jehanzeb.Javeed Monday, August 29, 2011 7:11 AM
-
Monday, August 29, 2011 9:36 AM
10x for the replay
tried this code:
function DynamicForm()
{
if (Xrm.Page.getAttribute("filed_value").getValue() == 90770000)
{
Xrm.Page.getAttribute("test_filed").SetVisible(false);
}
else
{
Xrm.Page.getAttribute("test_filed").SetVisible(true);
}
}
and when I change the field type (filed_value)
i get a popup massage:
hope to get your help
10x
-
Monday, August 29, 2011 9:41 AM
Hi,
You need to make correction in the setVisible function in the following code lines:
From
Xrm.Page.getAttribute("test_filed").SetVisible(false);
To
Xrm.Page.getAttribute("test_filed").setVisible(false);
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". -
Monday, August 29, 2011 9:54 AM
Hi,
i get the same error...
-
Monday, August 29, 2011 10:01 AM
Try this:
function DynamicForm() {
if (Xrm.Page.getAttribute("filed_value").getValue() == 90770000) {Xrm.Page.ui.controls.get("test_filed").setVisible(false);
}else {
Xrm.Page.ui.controls.get("test_filed").setVisible(true);
}
}
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". -
Monday, August 29, 2011 10:02 AMYou should use the real field names. It is very unlikely these names are test_filed and filed_value
-
Monday, August 29, 2011 10:07 AM
don't get any error now.
but it's doesn't do anything.
i change the value and nothing happens.
10x for replaying
-
Monday, August 29, 2011 10:11 AM
Hi,
Make one more change:
function DynamicForm() {
if (Xrm.Page.getAttribute("filed_value").getValue() == "90770000") {Xrm.Page.ui.controls.get("test_filed").setVisible(false);
}else {
Xrm.Page.ui.controls.get("test_filed").setVisible(true);
}
}
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". -
Monday, August 29, 2011 10:36 AM
still nothing
:(
don't get any errors.
but it doesn't do anything.
-
Monday, August 29, 2011 10:40 AM
Hi,
Make sure that you are using the correct field name and value, you may also try comparing text value, also make sure that you are using the funciton on field OnChange event and can post your code here:
function DynamicForm() {//instead of using getValue() you can use getText() to compare label text
if (Xrm.Page.getAttribute("filed_value").getValue() == "90770000") {Xrm.Page.ui.controls.get("test_filed").setVisible(false);
}else {
Xrm.Page.ui.controls.get("test_filed").setVisible(true);
}
}
Also your field wil be hide only if the selected OptionSet value will be 90770000
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Marked As Answer by bdap Monday, August 29, 2011 10:55 AM
-
Monday, August 29, 2011 10:54 AM
Try starting your function with:
alert(Xrm.Page.getAttribute("filed_value").getValue().ToString());
-
Monday, August 29, 2011 10:55 AM
Hi,
i'm glad to say that when i used the getText method it worked like a charm!
10x a lot!
-
Monday, August 29, 2011 10:59 AM
Try starting your function with:
alert(Xrm.Page.getAttribute("filed_value").getValue().ToString());
Hi ,
what does it do?
-
Monday, August 29, 2011 11:08 AMIn this case it is for debugging. It gives a popup with the actual value.
-
Monday, August 29, 2011 11:16 AM
OK
good to know.
and another thing that i need.
when using options set,
you can open the form with:
default value: unassigned value,
if i'm using getValue the value that I'll will put is "NULL"?
and when i use getText what would the value be?
10x
-
Monday, August 29, 2011 11:18 AM
Hi,
If you want to check for null then you can use:
if (Xrm.Page.getAttribute("filed_value").getValue() == null) {
or
if (Xrm.Page.getAttribute("filed_value").getText() == null) {
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".- Proposed As Answer by Jehanzeb.Javeed Monday, August 29, 2011 11:32 AM
-
Monday, August 29, 2011 11:59 AM
10x!
-
Monday, August 29, 2011 12:03 PM
is there any differences between getting value from
option set (regular)
option set (pick list)
and two options ?
10x
-
Monday, August 29, 2011 12:05 PM
Hi,
In TwoOptions you can get only two values either True or false i.e.
if (Xrm.Page.getAttribute("filed_value").getValue() == true)
{
}
If this answers your question then please Mark as Answer.
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". -
Monday, August 29, 2011 1:28 PM
Hi,
and what if i changed the default names of the options set?
-
Monday, August 29, 2011 1:42 PM
Some of the answers above must have been helpful to you. Please mark the all as helpful.- Proposed As Answer by Jan AS Monday, August 29, 2011 4:23 PM
-
Monday, August 29, 2011 1:44 PM
Hi,
TwoOption set will always return true or false values regarless of the label changing.
Jehanzeb Javeed
http://worldofdynamics.blogspot.com
Linked-In Profile |CodePlex Profile
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". -
Monday, August 29, 2011 3:09 PM
Hi,
when using picklist
how do I work with the getValue?
i tried using it the same as
if (Xrm.Page.getAttribute("picklist_value").getValue() == "90770000")
the value is from the options set field.
but when i'm marking the value it wont show the wanted field.
10x again for your help.
you are very helpful:)