Using Unibase session variables

Like many platforms Unibase provides session management. One of the session management functions allows the storing of variables in the session file. These variables are made available to the application as environment variables.

Storing a variable is done using the command ::unibase::session::var

Syntax:

::unibase::session::var <variable name> <value>

A subsequent call to ::unibase::session::var can be used to change the value of the variable. Variables can’t be deleted but can be set to the empty string.

To access this first load the unibase package

package require unibase

This will work fine in a script but to get it to work in ubprompt you must load tclsh explicitly. Make the first line of the tcl script:

#!/usr/bin/tclsh

followed by a blank line.

In this short example from a real application we ask the user to select a company branch and then add it to the session variables as RO_BRANCH. From that time on all programs run within this session can access $RO_BRANCH.

#!/usr/bin/ubprompt -wR

# selectBranch - Select a branch to work from
#
# Copyright 2023 - Unifacta Pty Ltd
#

P
branchId,       3       Fbranches       [branch]
>
<div class="prompt">
        <fieldset>
                <table> <tr><td>BRANCH</td><td>[branchId]</td></tr>
                        </table>
                </fieldset>
        </div>
>

V1
[branchId:T] != ""
You must select a branch
>

T       LOGIN BRANCH SELECTION

F1      SELECT
Click here to select your branch
>
#!/usr/bin/tclsh

package require unibase 1.0

::unibase::session::var RO_BRANCH [branchId]
exec >@stdout $UG_APP/bin/start_html

exit 0
>

In this longer example we select a sale type and staff number for a sale. Note that we initialise the staff number to the existing value (RO_STAFF) so that the same staff member doing multiple sales doesn’t have to keep entering their staff number. We then set the RO_STAFF to the new value in case it has been changed.

#!/usr/bin/ubprompt -wR

* posStart - start a POS transaction
*
* Copyright 2023 - Unifacta Pty Ltd
*

P
salespersId,    6       Fsalespers      [salespers_name]
ptsaltypId,     2       Fptsaltyp       [ptsaldesc]
>
<h1>POINT OF SALE - TYPE OF SALE</h1>
<div class="prompt">
        <fieldset>
                <div>Sale Type</div><div>[ptsaltypId]</div>
                </fieldset>

        <fieldset>
                <div>Sales Person: [salespersId]</div>
                </fieldset>
        <fieldset id="functionKeys"></fieldset>
        </div>
<iframe id="sale" scrollable></iframe>
>

S
[salespersId]   "$RO_STAFF"
>

V1
[ptsaltypId:T] != ""
Please select a sale type
[salespersId:T] != ""
Please select a Sales person
>

F1      SEARCH  Isale
Click here to start sale
>
#!/usr/bin/tclsh

package require unibase

exec >@stdout $UG_APP/bin/htmlHEAD --content

::unibase::session::var RO_SALETYPE [ptsaltypId]
::unibase::session::var RO_STAFF [salespersId]

::unibase::log::log posStart \[exec ubdump ptsaltyp -k ptsaltypId -m {[ptsaltypId]} -a {\[ptnext:T]}]
exec >@stdout {*}\[subst \[exec ubdump ptsaltyp -k ptsaltypId -m {[ptsaltypId]} -a {\[ptnext:T]}]]
>