NameValue

Description

Sets or returns the value associated with a given variable name.

Use this property to get and set the values for session-wide variables. Because this property consists of an array of values, you must specify the name of the variable you are interested in. If you set the value of a variable that does not exist, it is created with the specified value assigned to it. If you try to get the value of a variable that does not exist, an empty Variant is returned (for Visual Basic).

HCL Compass supports the use of session-wide variables for storing information. Once created, you can access session-wide variables through the current Session object at any time and from functions or subroutines, including hook routines, that have access to the Session object. When the current session ends, either because the user logged out or you deleted the Session object, all of the variables associated with that Session object are deleted. A Session-wide variable is accessed through the NameValue property (GetNameValue and SetNameValue methods for Perl). In addition, the HasValue method can be used to check whether a variable exists.

For example, there is a _CQ_WEB_SESSION session variable that specifies if a HCL Compass session is a web session or a full client session. If _CQ_WEB_SESSION exists, then the session is a Web session. You can check for this value using the HasValue method.

You can also store objects as session variables. For example:


set sessionObj.NameValue "Obj", object

or


set sessionObj.NameValue "CalendarHandle", param.ObjectItem

In the above example, param is the parameter to a record script hook and contains an object handle.

Elsewhere, you can then manipulate the properties of the object. For example:


Dim Calender

'Get the object handle

Set Calender = MySession.NameValue("CalendarHandle")

'Do something with the object ...

Syntax

VBScript


session.NameValue (variable_name)
session.NameValue variable_name, newValue 

Perl


$session->GetNameValue(variable_name);
$session->SetNameValue(variable_name, newValue); 
Identifier
Description
session
The Session object that represents the current database-access session.
variable_name
A String containing the name of the variable to get or set.
newValue
For Visual Basic, a Variant specifying the new value for the variable.

For Perl, a String specifying the new value for the variable.

Return value
For Visual Basic, a reference to a Variant containing the value for the variable.

For Perl, a String containing the value for the variable.

Example

VBScript


set sessionObj = GetSession 

' Get the old value of the session variable "test" 
testValue = sessionObj.NameValue("test") 

' Set the new value of "test" 
sessionObj.NameValue "test",bar 

Perl


$sessionObj = $entity->GetSession();

if ($sessionObj->HasValue("test")) {

# Get the old value of the session variable "test" 

$testValue = $sessionObj->GetNameValue("test");



# Set the new value of "test" 

$sessionObj->SetNameValue("test","bar");