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 :
Microsoft Dynamics CRM (Archived)

Field data is not loaded before script run - require.js

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

We recently refactored the scripts of CRM 2016 and implemented the require.js. After this, we found inconsistency during function call on OnLoad of entity forms. We found that during OnLoad event sometimes controls were not filled with data though function was executed and it skipped the code if control is null.

So to overcome this issue we used setTimeOut function. However it works but we would like to know if any other way to get know that is the control filled or not, or any other way so that we execute our scripts for OnLoad event only after data loading for fields.

Any kind of help is welcome from all of you.

*This post is locked for comments

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    Hi Jaspreet,

      normally, when you are in the OnLoad, it's safe to assume all controls have values - that's wha onLoad is for. Maybe you could post some code here so we could see how your Javascript looks like?

  • Community Member Profile Picture
    on at

    Hi Alex,

    Thanks for your reply.

    Actually we implemented require.js so we are not unig OnLoad event of form. We just calling the library of code in form properties and calling the function for OnLoad from webresource instead of OnLoad event of form.

    Can you suggest something with this bit input?

  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    I would advise against using requirejs like this because of the asynchronous loading nature - your entry point to your code must always be onload otherwise you cannot guarentee that the form is ready.

    If you are using requirejs for your dependencies then you need to use something like webpack to bundle the files together and then reference as a webresource in the form - then call your logic from the onload

    The biggest gotcha with requirejs AMD loafing is that Dynamics has no way of knowing your script dependances and so can’t cache or detect changes and make them available offline.

    Hope this helps

  • ashlega Profile Picture
    34,477 on at

    Hi Jaspreet,

     That's, likely, where the problem is. You cannot expect Xrm to be fully initialized until OnLoad happens, and it usually happens after the web resources have been loaded. Not sure what exactly you are doing, but I am pretty sure you just need to make it so that you don't try accessing Xrm before onload( just to be clear, I am talking about the OnLoad.event of the form, not about html onload)

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans