0

I have overridden the case resolve button to call my custom JavaScript. I will call this function custom_resolve_func(). That works fine. When I press the resolve button, custom_resolve_func() is invoked.

I have another function attached to the OnLoad event of a case form.. I will call this function custom_onload_func().That works fine. When I load the form, custom_onload_func() is invoked.

custom_resolve_func() and custom_onload_func() are in the same JS webresource.

My problem is how to have both funcs share data at runtime?

For example, In custom_onload_func() I set a variable global to the JS webresource. When I press the resolve button, invoking custom_resolve_func(), I read the same variable but its as if it never got set in custom_onload_func(). If I give it an initial value at time of declaration, that is the value I get when I read it in custom_resolve_func().

How can both funcs share the same context? I need custom_resolve_func() to be able to access the form context somehow...

Greg Owens
  • 3,878
  • 1
  • 18
  • 42
keerz
  • 717
  • 1
  • 6
  • 21

1 Answers1

1

The Ribbon is loaded in an IFrame, so you can't reach scripts loaded in Ribbon from scripts loaded on form. Moreover, I believe you have two scripts loaded.

So, I would try to load the script only on the form and putting a mock file into a Ribbon Command Definitions.

<JavaScriptFunction Library="mock.js" FunctionName="custom_resolve_func">

Or to store a variable in a hidden field on the form.

Grigory
  • 550
  • 3
  • 14
  • thanks for this. Not sure I fully understand. It does seem like I have 2 scripts loaded. Are you saying that custom_resolve_func() in mock.js should call custom_resolve_func2() in my form.js and that should work? Can you elaborate on the "store a variable in a hidden field on the form" idea? – keerz Nov 15 '12 at 14:57
  • @Greg I should say that it's not just 1 variable I need to share. What I really need is for custom_resolve_func() to be able to operate within the space of the JS that gets loaded with the form. I'll try the mock.js idea... – keerz Nov 15 '12 at 15:14
  • @Greg marking this as the answer with a caveat. By creating mock_func() in mock.js that calls custom_resolve_func() in the JS loaded by the form, everything works except the final call to Xrm.Page.ui.close() to close the form window. Xrm.Page.ui.close() has no effect when invoked in custom_resolve_func() but works when invoked from mock_func(). No idea why. – keerz Nov 15 '12 at 23:48
  • Hi. Sorry, saying mock.js I meant it is nonexisting script, just to reference nonexisting webresource with existing function in another webresource. But the main idea is the same, it's like two separate windows. :-) – Grigory Nov 16 '12 at 20:58
  • @Greg would that work? a non-existing web resource? Any idea why the ui.close() has to be in my mock.js for it to work? Trying to understand the contexts things operate in here... – keerz Nov 17 '12 at 01:26
  • It is working. But that's unsupported of course. Need to play with it for a while. As far as I see you don't see the variables from one context to another, but you can see functions. – Grigory Nov 17 '12 at 23:29