Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

Javascript TypeError: Cannot read properties of null (reading 'getValue')

Posted on by 134

Dear All,

I am new to CRM and trying to develop a functionality to show or hide 'MultiSelect choice' field based on the value from other field. Since there is a limitiation to achieve this using CRM business rule, I tried using JS to achieve this functionality. But I am facing below error when trying to do this using JS. I have checked all the word spellings and everything is correct.

TypeError: Cannot read properties of null (reading 'getValue')

Please find my below JS code. Is it possible to advise what needs to be corrected please?

function HideorShowAccessibilityAdjustments(executionContext)

{
var formContext = executionContext.getFormContext();
if (formContext.getAttribute("mntr_areanyreasonableadjustmentsrequired").getValue()!=0) {
formContext.getAttribute("mntr_AccessibilityAdjustments").setVisible(true);
formContext.getAttribute("mntr_NonAccessibilityAdjustments").setVisible(true);
}
else if (formContext.getAttribute("mntr_Areanyreasonableadjustmentsrequired").getValue()!=1) {
formContext.getAttribute("mntr_AccessibilityAdjustments").setVisible(false);
formContext.getAttribute("mntr_NonAccessibilityAdjustments").setVisible(false);
}
}

Thank You,

Gowtham

  • Gowtham89 Profile Picture
    Gowtham89 134 on at
    RE: Javascript TypeError: Cannot read properties of null (reading 'getValue')

    Fantastic..Thanks Guido..You saved my day!!

    It works perfectly after I made the suggested changes. Thanks a lot.

    Thank You,

    Gowtham

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    RE: Javascript TypeError: Cannot read properties of null (reading 'getValue')

    setVisible is a sub method of a getControl, so your code you will need to write

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

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

  • Gowtham89 Profile Picture
    Gowtham89 134 on at
    RE: Javascript TypeError: Cannot read properties of null (reading 'getValue')

    Hi Guido,

    Thanks for the response, Yes that did resolve the initial issue. But now I am facing the actual issue described below

    TypeError: formContext.getAttribute(...).setVisible is not a function

    In the JS code I am trying to show and hide 'Multi-Select' option field in CRM. Do I need to use a different function to make it work.

    Thank You,

    Gowtham

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,065 Moderator on at
    RE: Javascript TypeError: Cannot read properties of null (reading 'getValue')

    that error happens when the field you are referring to is not added to the form or doesn't exist.

    in the code you posted check the field "mntr_areanyreasonableadjustmentsrequired"

    pay attention that when you refer to fields inside javascript they are lowercase, so "mntr_AccessibilityAdjustments" should be "mntr_accessibilityadjustments" and "mntr_NonAccessibilityAdjustments" should be "mntr_nonaccessibilityadjustments"

    hope it helps

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,572 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,792 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans