Monday, February 11, 2008

Personal Substitution Variables

A cool feature of the Smart Space SDK is the ability to create a set of global Smart Space variables that can be used by any gadget. These are essentially name value pairs that are called LocalProperties in Smart Space.

I used this feature in my latest batch of Essbase gadgets. I wanted the ability to set the Time dimension member for all of my Essbase query gadgets in one place and not have to go to each gadget to change this member. I knew that one option would have been to use the Essbase Substitution Variable functionality found in the Essbase product. But I did not want to make this a variable for all Essbase users which is what the Essbase Substitution Variable would provide.

I created a simple MyVariables gadget that allows the user to create personal variables.




These variables can then be used by other gadgets. In the case of the Essbase gadgets, I implemented a special syntax whereby any member name that is preceded by two ampersands (&&TODAY) represents a local variable. When constructing the query, the Essbase gadget then makes a call to Smart Space whenever it encounters a member name with this syntax to get the value of that variable. It replaces the syntax (&&TODAY) with the variable value (“20080823”) and issues the query.

This is another example of the great new benefits of having Smart Space running on your client. It is the analytical footprint that will allow for powerful new capabilities such as creating your own personal substitution variables.


public String getPreference(String key)
{
return Services.PreferenceManager.LocalProperties.Load(key);
}

public void savePreference(String key, String value)
{
Services.PreferenceManager.LocalProperties.Save(key, value);
}

public void deletePreference(String key)
{
Services.PreferenceManager.LocalProperties.Remove(key);
}

public void getPreferences()
{
listViewVars.Items.Clear();
try
{
String[] sPrefKeys = Services.PreferenceManager.LocalProperties.GetAllKeys();

ListViewItem item = new ListViewItem();

foreach (String sPrefKey in sPrefKeys)
{
String sPrefValue = getPreference(sPrefKey);
item = this.listViewVars.Items.Add(sPrefKey);
item.SubItems.Add(sPrefValue);
}
this.Refresh();
}
catch (Exception e1) { }
}

No comments: