Hi,
I have a OptionSet field on form and i wrote a code to hide a tab on this form if specific item is selected, But if no item is selected, I've got an Error:
function showtab (executionContext){
formContext = executionContext.getFormContext();
var Title = formContext.getAttribute('cos_joblevel').getSelectedOption().text;
if (Title != null){
if (Title == "Apprentice")
{
formContext.ui.tabs.get("tab_evaluationformapprentice").setVisible(true);
}
else
{
formContext.ui.tabs.get("tab_evaluationformapprentice").setVisible(false);
}
}
}
Can anybody help me with this problem?
Thank you in advance!
var customerValue = Xrm.Page.getAttribute("cos_joblevel").getValue();
if (customerValue != null) {
// ...
} else {
// ...
}
check this article:
community.dynamics.com/.../don-39-t-use-getselectedoption-text
Hi, Thank you.
It works now.
Hi,
If that item is not selected, `formContext.getAttribute('cos_joblevel').getSelectedOption()` will be null, and then calling `text` will cause the error you see, it is recommended to be like what `Mehdi El Amri` said First judge whether it is null.
If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.
Best Regards,
Frank Gong
Hi,
You need to check if the selectedOption is not null.
if (formContext.getAttribute('cos_joblevel').getSelectedOption()!=null){
//yourCode
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148