This blog post was created with the assistance of AI to help explain complex Uniface concepts in a more accessible way.
If you're working with Uniface web applications, specifically Dynamic Server Pages (DSPs), you've probably encountered the websetocc
statement. Today, let's dive into what it does, when to use it, and how it differs from the regular setocc
statement! π
π€ What is websetocc?
The websetocc
statement is a specialized ProcScript command used in Dynamic Server Page components (DSPs). Its main purpose is to set the current entity and occurrence based on information received from the web client, rather than using position-based indexing.
Entity: Think of an entity as a table structure in your application - it defines what data fields are available.
Occurrence: An occurrence is like a specific row of data within that entity structure - it's the actual instance containing values.
Dynamic Server Page (DSP): A special type of Uniface component designed for web applications that can be updated dynamically at runtime.
β‘ How websetocc Differs from setocc
While both statements set the current occurrence, they work differently:
- setocc: Uses position numbers in a hit list (like "go to row 5") π
- websetocc: Uses entity names and occurrence IDs received from the web client (like "find the customer with ID 12345") π
This makes websetocc
perfect for web environments where you need to identify specific data records across HTTP requests!
π― When Should You Use websetocc?
Use websetocc
when:
- Working with Dynamic Server Pages (DSPs) π
- Processing user interactions from web browsers π»
- Managing entity occurrences in web applications π
- Handling form submissions or AJAX requests π€
π Syntax and Usage
The basic syntax is simple:
websetocc
That's it! No parameters needed because websetocc
automatically reads the entity information from the web request.
π§ Step-by-Step Implementation
Here's a typical workflow using websetocc
:
operation processWebRequest
public web
; Step 1: Load web data
webload
; Step 2: Reconnect to ensure data integrity
reconnect/readcheck
; Step 3: Set current occurrence based on web client data
websetocc
; Step 4: Process your business logic here
if ($status = 0)
; Success! Current occurrence is now set
; You can safely work with entity data
message "Processing occurrence: %%ENTITY.KEYFIELD%%"
else
; Handle errors (see error codes below)
message "Error setting occurrence: %%$procerror%%"
endif
end
π¨ Understanding Return Values
websetocc
provides helpful feedback through system variables:
Success Values ($status)
- 0: Success! β Current occurrence has been successfully set
- < 0: Error occurred β Check
$procerror
for details
Common Error Codes ($procerror)
- -1: General error - Entity is the outer entity of a Record component
- -1102: Entity not found - The requested entity name isn't painted on the component
- -1133: Occurrence not found - The specific occurrence couldn't be located
π οΈ Practical Example
Let's say you have a customer management DSP. When a user clicks on a specific customer in the web interface:
operation editCustomer
public web
; Load the request data
webload
; Reconnect to database
reconnect/readcheck
; Set current occurrence based on customer ID from web
websetocc
if ($status = 0)
; Now we can work with the specific customer
$webinfo("output") = "Editing: %%CUSTOMER.NAME%%"
; Perform your editing logic here
; The correct customer occurrence is now active
elseif ($procerror = -1133)
$webinfo("output") = "Customer not found!"
elseif ($procerror = -1102)
$webinfo("output") = "Invalid entity requested!"
else
$webinfo("output") = "Unexpected error occurred!"
endif
end
π‘ Best Practices
- Always call websetocc after webload and reconnect - This ensures proper data loading and connection state π
- Check $status after each websetocc call - Proper error handling prevents unexpected behavior π‘οΈ
- Use meaningful error messages - Help users understand what went wrong π’
- Only use in DSP components - websetocc is specifically designed for web environments π
π Conclusion
The websetocc
statement is an essential tool for managing entity occurrences in Uniface web applications. By understanding how it differs from setocc
and following the proper workflow (webload β reconnect β websetocc), you can build robust web applications that correctly handle user interactions and data management!
Remember: websetocc
bridges the gap between web client requests and your Uniface component's data processing, making it a crucial piece of the DSP puzzle. Happy coding! π
Keywords: Uniface, websetocc, Dynamic Server Pages, ProcScript
Top comments (0)