function firstPickListOnChange()
{
var firstPickListValue = Xrm.Page.getAttribute("new_ddl1").getValue();
var secondPickListControl = Xrm.Page.ui.controls.get("new_ddl2");
var secondPickListOptions = secondPickListControl.getAttribute().getOptions();
secondPickListControl.clearOptions();
switch(firstPickListValue)
{
case 100000001:
secondPickListControl.addOption(secondPickListOptions [0], 0);
secondPickListControl.addOption(secondPickListOptions [1], 1);
secondPickListControl.addOption(secondPickListOptions [2], 2);
break;
case 100000002:
secondPickListControl.addOption(secondPickListOptions [3], 0);
secondPickListControl.addOption(secondPickListOptions [4], 1);
secondPickListControl.addOption(secondPickListOptions [5], 2);
break;
}
}
Hello Prasad,
ReplyDeleteHow to implement this? can you add some steps and images, so that anyone novice to CRM like me can use your solution.
I am in urgent need. I don't know whether this is a full-proof solution or not, but i hope for.
I will post if i get some error.
Hi Puneet,
DeleteThe above logic is pretty simple.
Xrm.Page.getAttribute("new_ddl1").getValue(); // provide the first option set schema name
Xrm.Page.ui.controls.get("new_ddl2");// provide the second option set schema name
secondPickListControl.addOption(secondPickListOptions [0], 0); // here provide the option set values which you have..
Let me know if anything needed.
Hello Guru Prasad,
DeleteI have successfully implemented dependent pick-list with help of your approach.
One quick question, is this code is supported in UR 12, i heard Java-scripts are breaking in UR 12.
Few things are not supported in Chrome and FF.
Do you know your code is not breaking in UR 12. Did you test it with Code Validation tool from Microsoft?
Let me know please.
Thank You.
Hello Prasad,
DeleteI was wondering if you have got my previous question.
This is regarding UR 12 for Dynamics CRM 2011, I was asking if this code is breaking or not in UR 12 JavaScript changes as i heard many existing Java Scripts has to be re-written. The code validation tool can show to which category scripts belong to.
I have not implemented your code yet, but i was looking forward if you happen to know if your code is full-proof in UR 12 as well.
Thank You.
Hi Prasad,
ReplyDeleteGreat script. How do you get the selected option of the second picklist?. I have a picklist that is filled using the addOption function, but when i try to get the selected option i got an null error. It seems like nothing is added to the picklist,but it does :(
Couple of day getting this error and i can't resolve it.
Thanks in advance.
Hi Carlos,
Deleteuse the following script to get the selected option of the second picklist.
var secondPickListselectedValue = Xrm.Page.getAttribute("new_picklist2").getValue();
Let me know if the issue still exists!
Thanks,
Guru
Hi Guru,
DeleteI tried this way and i'm still getting null. The options are added but i can't take the value or the selected option.
I've tried to get the selected option on the onSave and onChange (picklist) event always get null. Have you tried this before?, Taking the value of a picklist filled dinamically? Don't know what else to do.
Thank you for your time,
Carlos
Hello Carlos,
DeleteLet me know if you have any difficulties applying Prasad's code. There is a little bit explanation needed to implement this code.
When i first implemented it i got the same error. but i got it working.
the catch is
secondPickListControl.addOption(secondPickListOptions [0], 0); // here provide the option set values which you have.
In this line [0] -- do not put the value of optionset, instead put the index number of the optionset.
This code is basically taking the current index number of the option on change event of control and assigns a new value to 0 or 1 or 2.. whatever you assign.
If it still not clear, email me and we can have a live session.
Thanks.
Carlos,
DeleteI have forgotten to mention my email, its sudip.chakrovorty@gmail.com ... email me if any issues you have Carlos.
Obviouly Guru Prasad is Guru of CRM here, but i am just taking the opportunity.
Thank you.
Sudip, Thanks a lot for the sharing!!!
DeleteWhere do you define the values of 100000001 and 100000002 ?
ReplyDelete