Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to fix invalid reference

Posted on by Microsoft Employee

I'm new to Dynamics CRM, with only a little background in JavaScript. I need some insight...

I'm trying to fix a form (Sales > Leads > New Lead) in a CRM project that someone else wrote but that has never worked correctly. The form contains a Product Categories list box that's apparently an iFrame within the main form.

New-Lead-page.png

Two web resources are associated with that list. One (new_PromptLeadProductPage.htm) has JavaScript functions onbodyload() and oncheck(). The other one (new_PromptLeadProductService.js) contains functions for fetching and sorting the product categories, including one named GetAllProducts.

The first line in onbodyload() is

var objProducts =parent.window.GetAllProducts();

When that line executes, I get an error in the console log, "Uncaught TypeError: parent.window.GetAllProducts is not a function".

What do I need in this statement in place of "parent.window" to refer to the function in the ...Service.js resource?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to fix invalid reference

    Thank you. This did get me past the current error. Of course, once that happened, a different error occurred, but it wasn't related to this issue. The old code was using SOAP and CRMFetchKit, and it will have to be replaced with oData queries. I have a lot of work to do!

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to fix invalid reference

    Use this:

    var objProducts =parent.GetAllProducts();

  • Suggested answer
    keyur7379 Profile Picture
    keyur7379 900 on at
    RE: How to fix invalid reference

    Hey ,

    First you have to make sure that  HTML resource (new_PromptLeadProductPage.htm) have ref of new_PromptLeadProductService.js . If not the you have to add new_PromptLeadProductService.js ref

    ex.

    add this between <head>{Add your ref here}</head>

    <script src="https://<Your CRM instance name>//WebResources/new_PromptLeadProductService.js" type="text/javascript"></script>

     


    Now you can directly access GetAllProducts(); this method

    ex :

    var objProducts =GetAllProducts();



    If helpful , please mark as verified.
  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How to fix invalid reference

    Hi,

    Can you try using the following code?

    var objProducts = window.parent.GetAllProducts();

    Hope this helps.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans