Answered by:
how to disable the optionset field ?

Question
-
hi all,
to disable a optionset field, I have done the following code pelase review this and let me know where I am wrong
function
update()
{
varfields = ['boardfile', 'psychological', 'medicalreleaseform'];
varformtype = Xrm.Page.ui.getFormType();
vararraylength = fields.length;
if(formtype == 2)
{
for(vari = 0; i < arraylength; i++)
{
vartitle = Xrm.Page.getAttribute(fields[i]).getSelectedOption().text;
alert(title);
if(title != null)
{
if(title == "Required")
{
Xrm.Page.getControl(fields[i]).setDisabled(
true);
}
}
}
}
}
Monday, June 16, 2014 11:23 AM
Answers
-
Hi,
I didn't get your requirement by looking at your code, which I cleaned up as follows:
function update() { var fields = ['boardfile', 'psychological', 'medicalreleaseform']; var formtype = Xrm.Page.ui.getFormType(); var arraylength = fields.length; if (formtype == 2) { for(var i = 0; i < array.length; i++) { var title = Xrm.Page.getAttribute(fields[i]).getText(); alert(title); if(title != null) { if(title == "Required") { Xrm.Page.getControl(fields[i]).setDisabled(true); } } } } }
So you have three OptionSet fields viz. "boardfile", "psychological" and "medicalreleaseform"; and if the option "Required" is selected in any of them, it is disabled. And all this applies of the Form Type is for update.
Is the above condition true? If not, please state your requirement and I shall try to provide the correct code.
- Marked as answer by Microsoft Dynamics CRM Wednesday, June 25, 2014 4:56 AM
Monday, June 16, 2014 11:35 AM
All replies
-
you want to remove entries of the optionset field (in your case called boardfile', 'psychological', 'medicalreleaseform')?
My blog: www.crmanswers.net - Rockstar 365 Profile
Monday, June 16, 2014 11:35 AM -
Hi,
I didn't get your requirement by looking at your code, which I cleaned up as follows:
function update() { var fields = ['boardfile', 'psychological', 'medicalreleaseform']; var formtype = Xrm.Page.ui.getFormType(); var arraylength = fields.length; if (formtype == 2) { for(var i = 0; i < array.length; i++) { var title = Xrm.Page.getAttribute(fields[i]).getText(); alert(title); if(title != null) { if(title == "Required") { Xrm.Page.getControl(fields[i]).setDisabled(true); } } } } }
So you have three OptionSet fields viz. "boardfile", "psychological" and "medicalreleaseform"; and if the option "Required" is selected in any of them, it is disabled. And all this applies of the Form Type is for update.
Is the above condition true? If not, please state your requirement and I shall try to provide the correct code.
- Marked as answer by Microsoft Dynamics CRM Wednesday, June 25, 2014 4:56 AM
Monday, June 16, 2014 11:35 AM -
Hi,
It is working fine but when the field is empty then it is returning, it is not running for the remaining fields.
I have declared it for 7 fields when the 5 field is empty then script is not running for the remaining 6 and 7 fields ...
Please help me how can I solve this issue.
Tuesday, June 17, 2014 6:33 AM -
Hi,
Is the script same as above? And on what event did you link it (form onload, form save, etc.)?
Tuesday, June 17, 2014 6:57 AM -
script is same , I called it onload.
Tuesday, June 17, 2014 7:47 AM -
Hi, I could not disable as the api couldn't do it. Ended up storing all the options and only showing the ones I needed. Disabling would have been a lot more elegant. DonaldTuesday, June 17, 2014 8:47 AM