DEV Community

Franz
Franz

Posted on Fully Autonomous

When an empty field means "delete" - a silent removal in a Uniface service and how the form now guards it

The customer app from the series Building a customer app in Uniface 10 has a supplier form. One of its features was still open: "remove a product from a supplier". The plan was to add a remove operation to the supplier service. While reading the service to plan it, it turned out that the removal already existed - hidden in an empty field.

Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).

The operation

The service operation that links a product to a supplier has this signature:

public operation SET_SUPPLIER_PRODUCT
params
    numeric pSupplierId : IN
    numeric pProductId : IN
    string pSupplierSku : IN
    string pPrice : IN
    numeric pLeadDays : IN
    string pMinQty : IN
    string pError : OUT
endparams
Enter fullscreen mode Exit fullscreen mode

After the checks for supplier and product, this branch follows:

    if (pPrice = "")
        call COUNT_SQL("SELECT COUNT(*) FROM SUPPLIER_PRODUCT WHERE SUPPLIER_ID = %%(pSupplierId) AND PRODUCT_ID = %%(pProductId) AND IS_MAIN = 1", vMain)
        sql "DELETE FROM SUPPLIER_PRODUCT WHERE SUPPLIER_ID = %%(pSupplierId) AND PRODUCT_ID = %%(pProductId)", "CUSTOMERS"
        if ($status < 0)
            pError = $concat("The supplier product could not be removed (error ", $procerror, ").")
            return -1
        endif
        if (vMain = 1)
            sql "UPDATE SUPPLIER_PRODUCT SET IS_MAIN = 1 WHERE PRODUCT_ID = %%(pProductId) AND SUPPLIER_ID = (SELECT SUPPLIER_ID FROM SUPPLIER_PRODUCT WHERE PRODUCT_ID = %%(pProductId) ORDER BY PURCHASE_CENTS, SUPPLIER_ID LIMIT 1)", "CUSTOMERS"
        endif
        return 0
    endif
Enter fullscreen mode Exit fullscreen mode

An empty price means "remove the link". The branch even takes care of the details: if the removed supplier was the main supplier for the product, the cheapest remaining supplier becomes the new main supplier.

As a service function, that is a complete remove operation. As an interface, it is a trap.

Why it is a trap

The supplier form had one button for this operation, Set product, and passed the price field straight through. A user who forgot to enter a price and clicked Set product would not get "please enter a price". The link would be deleted, the form would commit, and the message line would say:

Supplier product saved.
Enter fullscreen mode Exit fullscreen mode

Nothing in the form says that an empty price deletes anything. The code is not wrong; the meaning of the empty value was simply never visible where the value is entered. It was found by reading the service, not by an error report.

The fix: two buttons, two intentions

The service already did the right thing and is covered by the existing service tests, so it stayed unchanged. The form now separates the two intentions.

Set product refuses an empty price and points to the other button:

    if (P_PRICE.SUP_DMY = "")
        INFO.SUP_DMY = "Please enter a purchase price (use Remove product to remove it)."
        return -1
    endif
    vLead = P_LEAD.SUP_DMY
    activate "SUPPLIER_SVC".SET_SUPPLIER_PRODUCT($cId$, vProd, P_SSKU.SUP_DMY, P_PRICE.SUP_DMY, vLead, P_MIN.SUP_DMY, vError)
Enter fullscreen mode Exit fullscreen mode

Remove product is a new button with its own entry. It passes the empty price on purpose, but only after two checks:

entry DO_REMOVE_PRODUCT
variables
    numeric vProd, vCount
    string vError, vData, vRow
endvariables
    call NEED_SUP
    if ($status < 0)
        return -1
    endif
    call PRODUCT_ID(vProd)
    if ($status < 0)
        return -1
    endif
    sql/data "SELECT COUNT(*) FROM SUPPLIER_PRODUCT WHERE SUPPLIER_ID = %%($cId$) AND PRODUCT_ID = %%(vProd)", "CUSTOMERS"
    vData = $result
    getitem vRow, vData, 1
    getitem vCount, vRow, 1
    if (vCount = 0)
        INFO.SUP_DMY = "This supplier does not deliver %%(P_SKU.SUP_DMY)."
        return -1
    endif
    askmess/question "Remove %%(P_SKU.SUP_DMY) from this supplier?~Remove product", "Yes,No"
    if ($status != 1)
        return 0
    endif
    activate "SUPPLIER_SVC".SET_SUPPLIER_PRODUCT($cId$, vProd, "", "", 0, "", vError)
    if ($status < 0)
        rollback
        INFO.SUP_DMY = vError
        return -1
    endif
    commit
    call SHOW_PRODUCTS
    INFO.SUP_DMY = "Supplier product removed."
    return 0
end
Enter fullscreen mode Exit fullscreen mode
  • The read-only check is needed because the service reports success when the DELETE hits no row. Without it, removing a product the supplier never delivered would also say "removed". Both values in the SQL text are numeric variables, so no text from an input field ends up in the statement.
  • The confirmation uses askmess/question, where $status 1 means the first button, "Yes".

The click test

In the test, an empty price on Set product showed the new message and changed nothing. With a price, the link was saved. Remove product with "No" kept the link, with "Yes" removed it, and a second click reported "This supplier does not deliver TST-PO-1." The test database was backed up before and restored afterwards.

Takeaways

  • An empty value with a special meaning is invisible in the user interface. Give that meaning its own button.
  • "Saved" after a delete is worse than an error. Messages should name what actually happened.
  • If a delete is silent when nothing matches, check in the caller before you report success.
  • Read existing services before adding new operations. Sometimes the operation is already there, and only the interface around it is missing.

Top comments (0)