Using the iWidget persistent data store

Connections

When building iWidgets for IBM Connections, you oftentimes have the need to store data for an end user.  For example, you may interested in storing a user name, some preferences, etc.  Did you know that you can use the iWidget persistent data store to accomplish this?  This data store persists across browser sessions, the clearing of a browser cache, and even through server restarts!  It’s a great way to store some data.

When you use the data store, an HTTP request will be made to the Connections server any time you invoke the save operation.  For site performance reasons, you should probably limit the number of save operations you make.  For example, if you need to store lots of data, you should consider consolidating it into a single JSON object, and then write the serialized string to the data store.  This will allow you to save / retrieve all of your data with a single API operation.

So, that’s great.  How do you use it?  It’s very simple.  In your iWidget, you can use the following JavaScript API to save your data:


var attrs = this.iContext.getiWidgetAttributes();
attrs.setItemValue("MyKey", "MyValue");
attrs.save();

And here’s a code snippet demonstrating how to retrieve your data using JavaScript.


var attrs = this.iContext.getiWidgetAttributes();
var value = attrs.getItemValue("MyKey");

Enjoy your new iWidget capabilities!  You can now persist data across sessions and bring a more personalized experience to your end users!

You may also like...

1 Response

  1. June 9, 2014

    .

    tnx for info.

Leave a Reply