Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Javascript error help

(0) ShareShare
ReportReport
Posted on by 90

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);
}

}

  • Vinit_Bhagat Profile Picture
    Vinit_Bhagat 120 on at
    RE: Javascript error help

    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!

  • Inogic Profile Picture
    Inogic 24,102 on at
    RE: Javascript error help

    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!

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,087 Super User 2024 Season 1 on at
    RE: Javascript error help

    the error is with this

    vantage_CountiesServed

    you need to write the logical name so is lower case

    vantage_countiesserved

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans