Answered by:
CRM 2011 JS giving errors

Question
-
I added an OnLoad Event to my Opportunity Form. When the form loads I get the following error: "Object doesn't support property or method 'setDisable'. What am I doing wrong?
// *************************************************** \\
// Microsoft Dynamics CRM 2011 Java Script
// Name: New_Opportunity_New_Library
// Modified Date: 4/2/2015
// Company:
// Practice Area SubPractice Area Code
// *************************************************** \\function Form_OnSave()
{
}
function Form_OnLoad()
{
setDisableSubPracticeArea()
}
function setDisableSubPracticeArea(){
if (Xrm.Page.getAttribute("cpdc_primarypracticearea").getValue() == null){
// If the value is null set field sub-practice area disable field
Xrm.Page.getControl("cpdc_subpracticearea").setDisable(false);
}
else if (Xrm.Page.getAttribute("cpdc_primarypracticearea").getValue() != null){
// if value is not null then set visible sub-practicearea field
Xrm.Page.getControl("cpdc_subpracticearea").setDisable(true);
}
}Thursday, April 2, 2015 6:08 PM
Answers
-
Hi,
Use below code :
function Form_OnSave() {
}
function Form_OnLoad() {
setDisableSubPracticeArea()
}
function setDisableSubPracticeArea() {
if (Xrm.Page.getAttribute("cpdc_primarypracticearea").getValue() == null) {
// If the value is null set field sub-practice area disable field
Xrm.Page.getControl("cpdc_subpracticearea").setDisabled(false);
}
else if (Xrm.Page.getAttribute("cpdc_primarypracticearea").getValue() != null) {
// if value is not null then set visible sub-practicearea field
Xrm.Page.getControl("cpdc_subpracticearea").setDisabled(true);
}
}Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
Vikram Singh. !!! My Blog- Marked as answer by pegineb Thursday, April 2, 2015 8:26 PM
Thursday, April 2, 2015 7:01 PM
All replies
-
Hi,
Use below code :
function Form_OnSave() {
}
function Form_OnLoad() {
setDisableSubPracticeArea()
}
function setDisableSubPracticeArea() {
if (Xrm.Page.getAttribute("cpdc_primarypracticearea").getValue() == null) {
// If the value is null set field sub-practice area disable field
Xrm.Page.getControl("cpdc_subpracticearea").setDisabled(false);
}
else if (Xrm.Page.getAttribute("cpdc_primarypracticearea").getValue() != null) {
// if value is not null then set visible sub-practicearea field
Xrm.Page.getControl("cpdc_subpracticearea").setDisabled(true);
}
}Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
Vikram Singh. !!! My Blog- Marked as answer by pegineb Thursday, April 2, 2015 8:26 PM
Thursday, April 2, 2015 7:01 PM -
Hi Vikram,
Thank you so much for your help. The script works as expected!! Wonder if I also wanted to include an OnChange for this. How would I word it?
Wednesday, April 8, 2015 12:46 PM