Question Status

Unanswered
pavan mani deep yaragani asked a question on 27 Jan 2015 4:59 AM

Hi, I am using the following code where "If we select any value from the optionset,firstname should be read only",but i am getting an error--unable to get the property set disabled,if i chose some other field in place of first name,with any selection in the optionset that field is made readonly

code:

function firstnamereadonly()
{
  var option = Xrm.Page.getAttribute("new_contactrole").getOptions();
for(var i in option)
  {
   if(option[i].value == 4)
     Xrm.Page.getControl("firstname").setDisabled("true");
     else
     Xrm.Page.getControl("firstname").setDisabled("false");
   }
}

Thanks in Advance

Reply
Guido Preite responded on 27 Jan 2015 5:09 AM

Hi,

to check if an optionset value is selected (meaning not empty) you can just check the getValue result if is null or not:

var option = Xrm.Page.getAttribute("new_contactrole").getValue();
if (option != null) { ... }

or you can check if a specific value is selected;

var option = Xrm.Page.getAttribute("new_contactrole").getValue();
if (option == 4) { ... }

another thing is that when you use setDisabled you need to pass the values as boolean, not as string so it will be

Xrm.Page.getControl("firstname").setDisabled(true);

the final code can be:

function firstnamereadonly() {
var option = Xrm.Page.getAttribute("new_contactrole").getValue();
if (option == 4) {
    Xrm.Page.getControl("firstname").setDisabled(true);
} else {
    Xrm.Page.getControl("firstname").setDisabled(false);
}
}

Reply
pavan mani deep yaragani responded on 27 Jan 2015 6:29 AM

Used ur code,

unable to get "propery set disabled", was the error message

can you please check on this

Reply
Guido Preite responded on 27 Jan 2015 6:32 AM

check if the field firstname is inside the form.

and i you still get the error debug the javascript

social.technet.microsoft.com/.../3256.how-to-debug-jscript-in-microsoft-dynamics-crm-2011.aspx

Reply