Skip to main content

Notifications

Announcements

No record found.

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

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

Posted on by 140

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.

  • Aarnav Profile Picture
    Aarnav 125 on at
    RE: Getting error - as formContext.getAttribute.. is not a function

    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
  • Yiantheo Profile Picture
    Yiantheo 5 on at
    RE: Getting error - as formContext.getAttribute.. is not a function

    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

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Getting error - as formContext.getAttribute.. is not a function

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

  • snehaln676 Profile Picture
    snehaln676 140 on at
    RE: Getting error - as formContext.getAttribute.. is not a function

    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.

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Getting error - as formContext.getAttribute.. is not a function

    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
    snehaln676 140 on at
    RE: Getting error - as formContext.getAttribute.. is not a function

    Hello Clofly,

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

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: Getting error - as formContext.getAttribute.. is not a function

    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

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

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans