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 () {
    ......
  },
};
2
  • why don't you just load it like document.write('<script src="your script location.js"></script>') and call the method afterwards? hope i understood the question :D Commented Feb 20, 2012 at 9:23
  • Its inside CRM 2011 environment. And I need to call a method say _Context().. Commented Feb 20, 2012 at 9:44

2 Answers 2

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();
Sign up to request clarification or add additional context in comments.

3 Comments

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.
Yes just to reiterate what @DG. said, you should be able to keep both of these files separate
I think there's an issue linking those together when it comes to scripting executed from an IFRAME component. See this question 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.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.