Uniface Forms: Simplify Commit and Rollback Handling

Resumo

Pixel shares a reusable Uniface 10 AFTER_SAVE entry for handling service-call success and failure in CRM forms. The pattern commits or rolls back, reloads campaign data, and displays the right info-line message, with a button example using SQLite and Rocket Uniface 10.4.03.

DEV Community

One entry for commit and rollback after a service call in Uniface forms

The CRM forms in the series Building a customer app in Uniface 10 have many buttons that change data: add a participant, record a response, close a campaign, set a phase. Each button calls a service operation. After the call the form has to do the same four things every time: commit or roll back, reload what is shown, and put a message into the info line. 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 shared entry entry AFTER_SAVE
params
numeric pStatus : IN
string pError : IN
string pMessage : IN
endparams
if (pStatus < 0)
rollback
if (pError = "")
INFO.CMP_DMY = "Saving failed (status %%(pStatus))."
else
INFO.CMP_DMY = pError
endif
return -1
endif
commit
call LOAD($cCmp$)
INFO.CMP_DMY = pMessage
return 0
end
It takes the status of the service call, the error text the service returned, and the message for the success case. On failure it rolls back and shows the service's error. On success it commits, reloads the campaign and then shows the message. The message is set after LOAD, because LOAD writes its own text into the info line. A typical button entry DO_ADD
variables
numeric vStat
string vError
endvariables
call NEED_CMP
if ($status < 0)
return -1
endif
call NEED_CUST
if ($status < 0)
return -1
endif
activate "CAMPAIGN_SVC".ADD_TARGET($cCmp$, CUST_ID.CMP_DMY, vError)
vStat = $status
call AFTER_SAVE(vStat, vError, "Participant added.")
return $status
end
NEED_CMP and NEED_CUST check that a campaign is loaded and a customer ID was entered. Then the service is called, and the status is copied into vStat right away. The copy matters because the next statement is a call. After call AFTER_SAVE(...), $status holds the value that AFTER_SAVE returned, so return $status at the end passes the result of the whole action on. Keeping the service status in a variable makes it clear which status goes into AFTER_SAVE, and nothing between the activate and the call can change it. When the caller needs the status first Creating a new record is the exception. AFTER_SAVE reloads the current record, and for a new opportunity the current ID is only known after the service returned it: entry DO_CREATE
variables
numeric vId, vCampaign, vStat
string vError
endvariables
if ($cCust$ <= 0)
INFO.OPP_DMY = "Please choose a customer first."
return -1
endif
vCampaign = 0
if (CAMPAIGN_ID.OPP_DMY != "")
vCampaign = CAMPAIGN_ID.OPP_DMY
endif
if (PHASE.OPP_DMY = "")
PHASE.OPP_DMY = "QUALIFY"
endif
activate "OPPORTUNITY_SVC".CREATE_OPP($cCust$, TITLE.OPP_DMY, AMOUNT.OPP_DMY, PHASE.OPP_DMY, PROB.OPP_DMY, CLOSE_DATE.OPP_DMY, OWNER.OPP_DMY, vCampaign, vId, vError)
vStat = $status
if (vStat >= 0)
$cOpp$ = vId
endif
call AFTER_SAVE(vStat, vError, "Opportunity %%(vId) created.")
return $status
end
Here vStat is checked before AFTER_SAVE, to store the new ID in the component variable that LOAD uses. The same copied value then goes into AFTER_SAVE, so the check and the commit decision are based on one status. What the click tests showed Errors from the service reached the user unchanged, for example "The customer has not consented to contact by EMAIL." or "The campaign is closed.", and nothing was saved. Successful actions showed the reloaded record together with the message, for example "Response recorded." with the response and its time in the list. Notes One entry for "after the service call" means one place to change when the rule changes, for example how errors are shown. Copy $status into a variable directly after activate. Where a dry run is involved, the form should not roll back on success. The service decides what a dry run writes (that was a separate fix in the same stage).
Uniface Forms: Simplify Commit and Rollback Handling
Powered by Readybot.io

As últimas novidades de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …