A Uniface 10 customer app already had a full sales document form. For the common case, "customer calls, wants two items", it was too slow. So I added a small entry form: customer number, Q or O for quote or order, article number, quantity, Add line, Ctrl+A. This article shows the parts that were new to me.
Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, SQLite 3.50.2 via the SLE driver, November 2026.
The idea
The form has no database entity. The lines live in three component variables, each a Uniface item list (GOLD ; separated):
-
$cLines$:productId/quantityper line, this is what gets saved -
$cNets$: the net amount of each line in cents, for the running total -
$cTexts$: the display text, one line per entry
variables
numeric cCust, cPid
string cLines, cTexts, cNets
endvariables
Nothing touches the database until the user saves.
Price preview while typing
The quantity field has a loseFocus trigger. It normalizes the input through a service (decimal comma, at most three decimals) and refreshes the price label:
entry LEAVE_QTY
variables
numeric vMilli
string vNorm, vError
endvariables
if (F_QTY.@ = "")
return 0
endif
activate "SALESIN_SVC".PARSE_QTY(F_QTY.@, vMilli, vNorm, vError)
if ($status < 0)
INFO.@ = vError
return 0
endif
F_QTY.@ = vNorm
call SHOW_PRICE
return 0
end
The price itself comes from a service operation that asks the existing pricing service for the customer's price and discount, and computes the line net in SQLite to get the rounding right:
call GET_TEXT("SELECT CAST(ROUND(%%(vQty) * %%(vPrice) / 1000.0 * (10000 - %%(vBp)) / 10000.0) AS INTEGER) AS N", vNet)
Quantities are kept in thousandths, prices in cents, discounts in basis points, so all inputs are integers. For 10,5 pieces at 8,00 with 5 % discount the form shows line net 79,80 before the line is added.
Adding and removing lines
Adding a line appends to the lists with putitem and index -1:
vL = $cLines$
putitem vL, -1, $concat($cPid$, "/", vQty)
$cLines$ = vL
vL = $cNets$
putitem vL, -1, vNet
$cNets$ = vL
Removing the last line uses $itemcount and delitem on both lists. The display text is a multi-line string, so its last line is cut separately:
entry DO_REMOVE
variables
string vL, vT
numeric vN
endvariables
if ($cLines$ = "")
INFO.@ = "There is no line to remove."
return 0
endif
vL = $cLines$
vN = $itemcount(vL)
delitem vL, vN
$cLines$ = vL
vL = $cNets$
delitem vL, vN
$cNets$ = vL
vT = $cTexts$
if (vN = 1)
vT = ""
else
call CUT_LAST(vT)
endif
$cTexts$ = vT
call SHOW_LINES
INFO.@ = "Last line removed."
return 0
end
The running total is a forlist over the net list:
forlist vNet in $cNets$
vTotal = vTotal + vNet
vN = vN + 1
endfor
One save, all or nothing
Ctrl+A fires the form's accept trigger. It calls the save entry and returns -1, so the form stays open for the next document:
trigger accept
call DO_SAVE
return -1
end
The save passes the whole line list to one service operation. That operation only uses the existing sales document service (CREATE_DOC, ADD_PRODUCT_LINE, RECALC), so rights checks, number ranges and tax calculation stay in one place. If any line fails, it rolls back:
forlist vItem in pLines
vPos = $scan(vItem, "/")
if (vPos < 2)
pError = "A line could not be read (%%(vItem))."
rollback
pDocId = 0
pDocNo = ""
return -1
endif
vLen = vPos - 1
vPid = vItem[1:vLen]
vLen = $length(vItem) - vPos
vPos = vPos + 1
vQty = vItem[vPos:vLen]
activate "SALESDOC_SVC".ADD_PRODUCT_LINE(pDocId, vPid, vQty, vLineId, pError)
if ($status < 0)
rollback
pDocId = 0
pDocNo = ""
return -1
endif
vN = vN + 1
endfor
The form commits only after the operation returned successfully:
activate "SALESIN_SVC".QUICK_DOC(F_TYPE.@, $cCust$, $cLines$, vDocId, vDocNo, vError)
if ($status < 0)
rollback
INFO.@ = vError
return -1
endif
commit
Do not lose lines on close
The quit trigger asks before discarding unsaved lines. Returning -1 keeps the form open:
trigger quit
if ($cLines$ != "")
askmess/question "The lines have not been saved as a document. Close anyway?~Close", "Yes,No"
if ($status != 1)
return -1
endif
endif
return 0
end
One lesson from the tests
The form turns Q and O into QUOTE and ORDER in a loseFocus trigger. The automated test calls the service directly with "q", and the first run failed with "The document type must be QUOTE or ORDER." A field trigger only helps users of that form. The service now accepts the short forms too:
vType = $uppercase(pType)
call TRIM_TEXT(vType)
if (vType = "Q")
vType = "QUOTE"
endif
if (vType = "O")
vType = "ORDER"
endif
If a rule matters, put it in the service; the trigger is a convenience on top.
Summary
- Item lists in component variables are a light way to collect lines before anything is written.
-
putitemwith-1appends,$itemcountplusdelitemremoves the last item. - Compute money in integers (cents, thousandths, basis points) and round once, in SQL.
- Write the whole document in one service call and roll back on the first error.
-
acceptandquittriggers withreturn -1turn Ctrl+A into "save and continue" and protect unsaved input.
Top comments (0)