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 TypeError: Cannot read properties of null (reading 'getValue')

(0) ShareShare
ReportReport
Posted on by

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

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

    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

  • Gowtham89 Profile Picture
    on at

    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
    54,086 Moderator on at

    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
    on at

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

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

    Thank You,

    Gowtham

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 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans