Dynamics CRM 2011 · Javascript

CRM 2011 Execution Context Shared Variable vs JavaScript Shared Variable

Writing JavaScript is one of the easiest way to enrich user experience. And sometimes you need to store some values for the lifetime of the form.

CRM 2011 has a new feature to pass execution context to JavaScript function as its first parameter. This execution context has two relevant function in:

  • setSharedVariable(key, value)
  • getSharedVariable(key)
This is all good and well, however, be aware that the shared variable only available for the execution context, that is for the lifetime of the event. If you have JavaScript REST callback function, this will work well for you. Unfortunately NOT for storing values for the lifetime of the form.
For storing values for the lifetime of the form, we can use JavaScript window property.
// Setting a variable
window.myValue = 'Hello World!';
// Getting a variable
alert(window.myValue);
For dynamic variable, there is alternate way.
var i = 1;
// Setting a variable
window['myValue' + i] = 'Hello World!';
// Getting a variable
alert(window['myValue' + i]);

Cheers – Sy

Advertisements

3 thoughts on “CRM 2011 Execution Context Shared Variable vs JavaScript Shared Variable

    1. Hi Juan, thank you for the comment. Since it is a direct interaction with the HTML DOM, it is not supported.

      In saying that, in some cases it is worth taking the risk doing unsupported customizations when the value delivered exceed the risk.

      Cheers,
      Sy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s