Create a session

Usually, when a KCM Core job is started, it is not associated with a session. A script can choose to create a new session using the command CreateSession.

CreateSession;

When the command CreateSession completes, the running job is associated with a newly created session, and KCM Core generates the following:

  • Session identifier (available through the constant _sessionid)
  • Session directory under the instance Work directory that resides in [drive:]\KCM (available through the constant _sessiondir)

The script can store persistent data into the session directory, such as an XML file received from the client application.

ReceiveFile
  Src("data_for_the_session.xml")
  Dest("data.xml" [_sessiondir,]);

This example requests a file from the client application and stores it in the file "data.xml" in the session directory. It is also possible to store single string values into the session. For example, this SetSessionParameter command stores the value "3.14" in the session parameter my_stored_info.

SetSessionParameter
  Par ("my_stored_info")
  Value ("3.14");

The stored data remains available until the session is explicitly cleaned up. To gain access to the session later, it is important to store the session identifier, which is the key by which the session is accessed. You can do so by sending the session identifier to the client application with the function exchange_data.

Var Text Dummy = exchange_data ("SessionID", _sessionid, 0);

The client application must store the session identifier appropriately, so that it can pass it to subsequent KCM Core jobs that require access to the data from the session.

Templates can read session parameters using the session_parameter function. Templates cannot change session parameters, but they can use the _Document Field Set instead to pass data back to the KCM Core script that can access these using the document_metadata function. For more information on the document_metadata function, see document_metadata (k).