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

Notifications

Announcements

No record found.

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
    686 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 144 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans