Hi,
I'm having some difficulty creating some JavaScript, I require a Navigation item to hide based on a optionset value onload, I can get this to work for existing records but when I create a record I get the below error: my code is also below - Any assistance
would be greatly appreciated, I'm still a novice with JS when implementing with a CRM solution - I suspect that the issue lies with the optionset value on create is a unassignmed valuee (null) so some extra code is required.

function hidenavsites()
{
if(Xrm.Page.getAttribute("new_value").getSelectedOption().text =="1")
{
Xrm.Page.ui.navigation.items.forEach(function (item, index)
{
var itemLabel = item.getLabel();
if (itemLabel =="Company") {
item.setVisible(false);
}
})
}
}