Shared variables in Javascript

Let’s say we have two opened HTML web resources that need to share data between them. Sometimes, we have a hard time trying to do this as XRM Object Model does not have any out of the box method to handle this. However, here is where localStorage comes into play.


// In Web Resource A:
// Create a new local storage variable called: Name.
// Also, set its value as: "Jhon"
localStorage.setItem("Name", "John");

// In Web Resource B:
// Retrieve data from local storage variable
// created in web resource A
var Retrieved_Value = localStorage.getItem("Name");

// *Your logic using the retrieved data*

// Remove variable and data from localStorage to
// optimize resources
localStorage.removeItem("Name");

With these two lines of code, we’re able to share data between two components in MS Dynamics CRM.

Note: localStorage is not limited to MS Dynamics CRM, as it can be used outside as well.

Let me know any questions!

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s