UNIBASE

Variables: A guide to session management

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

While this functions correctly in a script, using it in ubprompt requires you to explicitly load tclsh.

Make the first line of the tcl script:

#!/usr/bin/tclsh

followed by a blank line.

In this real application example, the system prompts the user to select a company branch and then stores their selection as the RO_BRANCH session variable. 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 example, the system guides the user to select a sale type and staff number. It initializes the staff number field with the current RO_STAFF value, pre-filling the field for staff members processing multiple sales and reducing repetitive data entry. The system then updates the RO_STAFF session variable with the newly selected staff number if the user changes the value.

#!/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]}]]
>

Verified by MonsterInsights