web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript onLoad of quick create form

(0) ShareShare
ReportReport
Posted on by

Hello all,

I am trying to run some custom JavaScript on load of a quick create form. Here is an example of the code i am using.

var goalName = Xrm.Page.getAttribute("enc_name");
goalName.setValue("test");

The error i am getting is the following: "TypeError: Cannot read property 'setValue' of null"

I tried to debug my code in the browsers console, but it seems to be working on all levels.

Can anyone assist me with this?

Thank You!

Leibish Ringel

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at
    RE: JavaScript onLoad of quick create form

    Hi,

    Quick create for will load before fields loaded, just use timeout to get the field details or try with "Legacy form rendering" setting under Administration.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: JavaScript onLoad of quick create form

    Hi

    I think quick create forms run the load event for javascript before the page pops up. So you cant use the load event to get any fields.
    No matter what field you are trying to get, you should get that error. (but you could try and test if you are able to read other fields.)

    I have seen people suggest that you can place a dummy iframe on the page, because the iframe has a onreadystatecomplete that you can use to trigger the script.
    But i haven't testet this.

    I haven't found anyway to reach the ready event on a quick create form. But if you can, that might be another option instead of load.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: JavaScript onLoad of quick create form

    Normally to set value of a fields single line code is enough-

    Xrm.Page.getAttribute("enc_name").setValue("test");

    As error clearly says that " TypeError: Cannot read property 'setValue' of null"

    Which means either field name  "enc_name"  is wrong or the Xrm.Page.getAttribute("enc_name") getting null.

    Make sure the field name is correct and the fields exists in the form.

  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: JavaScript onLoad of quick create form

    Do a fail safe approach like this.

    var goalName = Xrm.Page.getAttribute("enc_name");

    if(goalName != null){

       goalName.setValue("test");

    }

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: JavaScript onLoad of quick create form

    Hi Leibish,

    Based on the error, it simply means that the Js is unable to find the attribute with the name "enc_name". Check if you have this field on the form. Also, are you sure that this is coming from this statement? It is possible that you have setvalue somewhere else which could be causing this issue?

    Hope this helps.

  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: JavaScript onLoad of quick create form

    hi..

    Is attribute with name enc_name is on quick create form. if attribute is not present on form  then you cannot set value using javascript.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans