web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Javascript error help

(0) ShareShare
ReportReport
Posted on by 92

I am not well versed in Javascript but I am trying to hide/show two different drop down (Choise) fields based on the value of another Choice field. Since I can't use Business Rule on a multi choice field I am stuck with Javascript.

Error message: Cannot read properties of null (reading 'setVisible')

My code

________________________________________________________________________________________________________

function HideFields(executionContext)
{
var formContext = executionContext.getFormContext();

var typeOfServiceProviderValue = formContext.getAttribute("vantage_typeofserviceprovider").getValue();

if (typeOfServiceProviderValue == 218700000)
{
formContext.getControl("vantage_typeofsupportiveservicesneeded").setVisible(true);
}
else
{
formContext.getControl("vantage_typeofsupportiveservicesneeded").setVisible(false);
}

var businesstype = formContext.getAttribute("businesstypecode").getValue();

if (businesstype == 809600001) //Service Provider
{
formContext.getControl("vantage_CountiesServed").setVisible(true);
}
else
{
formContext.getControl("vantage_CountiesServed").setVisible(false);
}

}

I have the same question (0)
  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    the error is with this

    vantage_CountiesServed

    you need to write the logical name so is lower case

    vantage_countiesserved

  • Inogic Profile Picture
    748 on at

    You faced the following error because a wrong logical name was passed for the field (vantage_CountiesServed). Please try again by passing the correct logical name to the setVisible() method.

    Hope this helps.

    Thanks!

  • Vinit_Bhagat Profile Picture
    102 on at

    Hi VANTAGE,

    It seems that you are passing a schema name of the field. You just need to pass the logical name instead of schema name.

    Your code should be,

    if (businesstype == 809600001) //Service Provider

    {

    formContext.getControl("vantage_countiesserved").setVisible(true);

    }

    else

    {

    formContext.getControl("vantage_countiesserved").setVisible(false);

    }

    Thanks!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 202 Super User 2026 Season 1

#2
CU11031447-0 Profile Picture

CU11031447-0 100

#3
NeerajPawar Profile Picture

NeerajPawar 70

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans