I want to hide a tab in Quote entity based on value of statecode field of quote entity.
Senario: If the value is equal to ''3'' tab should be visible, if not tab should be invisible. You can find my code below but it's not working.
Please help, thanks.
function hideTab(){
var field = Xrm.Page.data.entity.attributes.get("statecode");
if (field == null || field.getValue() == null)
return;
var value = field.getValue();
if(value != "3")
return;
Xrm.Page.ui.tabs.get(tab_9).setVisible(false);
}
In order to read the field value using JavaScript, the field must be in the body
of the crmForm (i.e. not in Header or Footer areas).
Additionally, I would refactor your code like this
function hideTab (){
var field;
var fieldValue;
var isHidden = false;
field = Xrm.Page.data.entity.attributes.get("statecode");
if (field != null && field.getValue() != null){
fieldValue = field.getValue();
alert(fieldValue);
if(value != "3")
isHidden = true;
}
alert(isHidden);
Xrm.Page.ui.tabs.get('tab_9').setVisible(isHidden);
}
Notice I've added a couple of alerts
so that you can check that