Due to limitations in implementation, the scripting API is unable to return an array of
sessions, users, certificates, or AltText objects. Instead, it returns a helper object of
the corresponding list class, that is, SessionList, UserList, CertificateList, or
AltTextList respectively.
These helper classes offer functions to access the items in the list, identical to the
functions offered by the list classes in the flow element module (JobList etc).
//dataset is a Dataset object with a CP2 model
var sessions = dataset.getAllSessions();
for(var i = 0; i < sessions.length; i++){
var session = sessions.at(i);
//..do something with session
}
Implementation note on Exceptions
The scripting API does not throw exceptions. All C++ toolkit exceptions must be caught
within each scripting API function. In some cases the scripting API function description may
describe what to do if an exception is caught (for example, return a null object). In many
other cases, the scripting API states that the result is undefined or there simply is no
described (or obvious) behavior. The recommended exception handling is as follows:
- Issue an error message to the Switch message log, describing as clearly as possible
what the problem is and what caused it.
- Provide stable behavior, even if the requested function cannot be executed. For
example, when writing to a read-only object, do nothing at all other than issuing an
error message.
- Avoid performing an operation partially; try to execute every operation completely or
not at all.