3

There is one JavaScript web resource in CRM 2011 called new\_/Script/genericJScript.js. Which contains some functions say, \_retrieveRecord() and \_Context() as below. And I need to call these methods from another JavaScript web resource called new\_/Script/testJScript.js. How can we do this?

if (typeof (MyTest) == "undefined")
{
  MYTEST = { __namespace: true };
}

MYTEST.RESTCALL = {
  _Context: function () {
    ......
  },

  _retrieveRecord: function () {
    ......
  },
};
Charan Raju C R
  • 758
  • 5
  • 21
  • 43

2 Answers2

4

Assuming you include both resources on your form (I am assuming you are doing this from), the following should be valid:

webresource1.js

function HelloWorld() {
  alert('Hello, world!');
}

webresource2.js

//should alert 'Hello, World!' using the method from the other webresource
HelloWorld();
glosrob
  • 6,631
  • 4
  • 43
  • 73
  • Its not usually necessary to keep all code on the same page, but it is necessary that any function call contained in one file does not happen before the file containing the function definition has loaded. – DG. Feb 20 '12 at 15:31
  • 1
    Yes just to reiterate what @DG. said, you should be able to keep both of these files separate – glosrob Feb 20 '12 at 19:01
  • I think there's an issue linking those together when it comes to scripting executed from an IFRAME component. See [this question](http://stackoverflow.com/questions/13777660/calling-a-js-function-from-html-iframe-both-web-resources) linking to this one. I'll give it a whack myself because it's interesting why he doesn't get that to work when we do. – Konrad Viltersten Dec 08 '12 at 13:03
1

I think the answer is simply to call MYTEST.RESTCALL._context()

DG.
  • 3,417
  • 2
  • 23
  • 28