Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Javascript error help

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,031 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,065 Moderator 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

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,570 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,683 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans