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

Getting error - as formContext.getAttribute.. is not a function

(0) ShareShare
ReportReport
Posted on by 144

Hello,

I have a java script function on load of the form which eventually calls - formContext.getAttribute("new_fieldame").addOnChange(fucntionname).

But on load of new lead form or existing lead form, following error is occurred -

formContext.getAttribute(...).addOnChange is not a function

This error was not occurring on other environment (having same JS, same form), however I could reproduce it by removing that field 'new_fieldname'.

On-load function gets called when complete form is loaded. However, I think the field is not getting loaded here.

Any idea about the occurrence of this error?

Thanks in advance.

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at

    Hi Partner,

    You could check whether "new_fieldname" is actually the logical name of that field.

    I recommend to use Level up for Dynamics 365/Power Apps plugin of Chrome, after the plugin has been installed,

    click the "logical name" menu to get logical name of all fields of form quickly.

    pastedimage1597389156546v1.png

    Regards,

    Clofly

  • snehaln676 Profile Picture
    144 on at

    Hello Clofly,

    I have checked the field name and 'new_fieldname' is the logical name of the field.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Can you confirm that field is available on the form? Without field available on the form getAttribute will return null so your code will fail.

  • snehaln676 Profile Picture
    144 on at

    I have the field on header of the form and not anywhere else on form. However I am accessing it with 'new_fieldname' only (instead of header_new_fieldname). It works on one environment, form gets loaded properly. But, it fails on another environment (replica of the 1st environment) where I get above mentioned error.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    My recommendation - place it somewhere on the form and uncheck "Visible" checkbox in the properties - that should fix your issue.

  • Yiantheo Profile Picture
    5 on at

    I have the exact same issue, did you find a solution to this? mine is  formContext.getAttribute(Applikata.Grade.Fields.Exam(true)).addOnChange(CalculateResult); and the field is alright in the form

  • Aarnav Profile Picture
    125 on at

    The form will pass global context , not the formContext , so you will need to get formcontext before calling getAttribute method.

    formContext.getFormContext().getAttribute("new_fieldname");
     assuming 'formContext' is the name of the argument in your function.

    [quote user="PD_0504"

    Hello,

    I have a java script function on load of the form which eventually calls - formContext.getAttribute("new_fieldame").addOnChange(fucntionname).

    But on load of new lead form or existing lead form, following error is occurred -

    formContext.getAttribute(...).addOnChange is not a function

    This error was not occurring on other environment (having same JS, same form), however I could reproduce it by removing that field 'new_fieldname'.

    On-load function gets called when complete form is loaded. However, I think the field is not getting loaded here.

    Any idea about the occurrence of this error?

    Thanks in advance.

    [/quote

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 61

#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