rbf_setSessionData()

Purpose

This function sets user session data as a key/value pair. This data is stored in the Platform session and can be accessed using the function rbf_getSessionData() and removed using the function rbf_removeSessionData(). The maximum number of key/value pairs is 50. If you set a value for an existing key, the new value overrides the previous value.

If this function raises an error, Platform sets the HTTP status to 500 and invokes the callback function provided via rbf_setErrorsCallback() and passes that function one of the following messages:

  • Empty Key Received — No input was passed
  • Invalid Input — Input was in the wrong format
  • Limit Violation. Max Allowed: 50 keys reached — User has already stored the maximum of 50 key/value pairs

Note: If this function call results in an error, and you have not configured a callback function using rbf_setErrorsCallback(), you will still see the HTTP status of 500 but will not see the reason for the error.

Syntax

rbf_setSessionData(key, value, callback);

Parameters

key

A string that is the lookup key for user session data. The maximum length of a key is 50 characters.

value

The value associated with key. The value can be a boolean, number, string (maximum length is 1000 characters), or null (where null is the value).

callback

The callback function that will receive a JSON array of picklist items as its first parameter.

Note: This API is not supported in portals.

Return value

If successful, passes the string "Session Data set successfully" to callback and sets the HTTP status to 200.

Example

The following example sets a key/value pair:

<script>
  var callback = function(errMsg, apiName) {
      alert("ERROR: "+errMsg+" in: "+apiName);
      };
      rbf_setErrorsCallback(callback);
  var handleSessionData = function (response) {
    if(console){
      console.log("**** Processing handleSessionData ****");
      console.log("Response is: ", response);
    }
  }
  rbf_setSessionData("name1", "John", handleSessionData);
  </script>

The following example passes no input and results in an error:

<script>
  var callback = function(errMsg, apiName) {
      alert("ERROR: "+errMsg+" in: "+apiName);
      };
      rbf_setErrorsCallback(callback);
  var handleSessionData = function (response) {
    if(console){
      console.log("**** Processing handleSessionData ****");
      console.log("Response is: ", response);
    }
  }
  rbf_setSessionData();
  </script>

Because no input was passed, Platform displays the following alert:

Empty Key Received Message