Add Method - Sessions

This method is used to create and return a new Session Object.

Client support

   Newlook Smartclient only.

Version Support

Introduced in Version 11.1 for Smartclient.

Syntax

Sessions.Add(name, [options])

Arguments

name- (String, Required)

String expression that specifies the name of the new session. The following names will generate a runtime error if used:

options- (Structure, Optional)

A structure containing the startup parameters to be passed to the method. It consists of one or more name/value pairs in the format name: "value", as listed in the table below.

Use options to specify the action that should be initiated when the session is created, and the specifics for that action.

The following example will initiate a connection named "MyIBMi" when the session starts:

{

StartupType: "Connection",

Startup: "MyIBMi"

}

The options argument can also define a list of variables that will be created for (and scoped to) the new session.

Name

Type

Comments

StartupType

Constant

(Required) One of the pre-defined StartupType constants (see below). Determines the type of action initiated when the session is created.

Startup

String

(Required) Name of the item to be opened or executed when the session is created. This value will be dependent on the value specified in the StartupType property. See StartupType constants.

OnCustomEvent

String

(Optional) Name of the script or macro to execute when a custom event is triggered in the session being created. Specifying this parameter assigns the Session.OnCustomEvent property.

Variables

Structure

(Optional) Name/value pairs which will be defined as variables for the new session.

Invalid options will result in a runtime error.

StartupType constants

Unlike the startup session (where any 'Startup' logic present in the solution will be automatically executed), there is no default startup logic for sessions that are created using the Add method. If the StartupType property is left blank, then the session does nothing when it is created.

StartupType constant

Product Support

Associated Startup value

Connection

All

Name of the connection to initiate.

File

All

Name of the .nl file to open.

Form

All

Name of the form to open.

Logic

All

Name of the script or macro to execute.

Use

Newlook must always have at least one session running. For this reason, each time Newlook* starts, a new session is automatically created and any 'startup' logic present in the solution is automatically executed. This session, which can be returned by the Sessions.StartupSession property, cannot be removed at runtime and remains running until Newlook is shutdown.

*Newlook, in this context, can mean Smartclient, the Smartframe Newlook control, the embedded Newlook control, or the Newlook Developer runtime client.

The Add method is used to create additional sessions at runtime. It creates a new Session object in the Sessions collection.

Sessions created using this method do not execute 'startup' logic when they are initiated; instead, they execute whatever action is specified in the options argument of the Add method.

Unlike the StartupSession, sessions created at runtime can be destroyed via the Remove method.

Returns

This method returns an instance of SessionObject.

Examples

J SCRIPT

// No options (a session titled 'EmptySession' will be created, but nothing will happen in the session).

Sessions.Add("EmptySession");

 

 

// Connect to connection called 'MyIBMi'.

Sessions.Add("Session2", { StartupType: "Connection", Startup: "MyIBMi" });

 

 

// Open NL file 'MyFolder/MyNLFile.nl'

Sessions.Add("Session3", { StartupType: "File", Startup: "MyFolder\\MyNlFile.nl" });

 

 

// Execute logic module 'MyLogic'

Sessions.Add("Session4", { StartupType: "Logic", Startup: "MyLogic" });

 

 

// Start session and define session variables 'MyVar1' and 'MyVar2'

var sessionOptions =

{

  Variables:

  {

    "MyVar1": 10.0,

    "MyVar2": "SomeValue"

  }

};

Sessions.Add("Session5", sessionOptions);

 

 

// Connect to 'MyIBMi' with pre-defined session variables

var sessionOptions =

{

  StartupType: "Connection",

  Startup: "MyIBMi",

  Variables:

  {

    "MyVar3": 20.5,

    "MyVar4": "Another Value"

      }

};

Sessions.Add("Session5", sessionOptions);

 

 

// Set an event callback for the session

var sessionName = "Helper";

var sessionOptions =

{

  StartupType: "Logic",

  Startup: "HelperStartup",

  OnCustomEvent: "Events.OnHelperCallback"

};

Sessions.Add(sessionName, sessionOptions);

 

See Also

Sessions Collection | Working with sessions | Session Object | ActiveSession Property | StartupSession Property | Remove Method - Sessions | SetActiveSession Method

Applies To

Sessions Collection


© 2004-2021 looksoftware. All rights reserved.