DEV Community

Peter + AI
Peter + AI

Posted on

Understanding Uniface 10.4 $clearselection: Managing Entity Selections Made Easy 🧹

This blog post was created with AI assistance to help developers understand this essential Uniface feature.

What is $clearselection? πŸ€”

The $clearselection operation in Uniface 10.4 is a built-in entity operation that clears the $selected attribute of all occurrences within an entity. Think of it as a "reset button" that deselects all previously selected records in your data collection at once.

Understanding Key Terms πŸ“š

Before diving deeper, let's clarify some important Uniface concepts:

  • Entity: A logical grouping of related data fields, similar to a database table
  • Occurrence: A single record or instance of an entity, like a row in a database table
  • $selected attribute: A built-in Boolean attribute that indicates whether a specific occurrence is selected (1) or not (0)
  • $collhandle: A collection handle that provides access to a set of entity occurrences
  • Built-in operation: Predefined functions provided by Uniface that perform common tasks

Basic Syntax and Usage πŸ“

The syntax for $clearselection is straightforward:

$collhandle { ( Entity ) } -> $clearselection()
Enter fullscreen mode Exit fullscreen mode

How Selection Works in Uniface ⚑

In Uniface, users can select individual occurrences either through the user interface or programmatically. When an occurrence is selected, two important things happen:

  • The occurrence's $selected attribute is set to 1
  • The occurrence is added to the collection of selected occurrences

Practical Example πŸ› οΈ

Let's say you have a customer entity with multiple customer records, and several have been selected for processing. Here's how you would clear all selections:

; Clear all selections in the CUSTOMER entity
$collhandle(CUSTOMER) -> $clearselection()

; After this operation, all customer occurrences 
; will have their $selected attribute set to 0
Enter fullscreen mode Exit fullscreen mode

Real-World Use Cases πŸ’Ό

The $clearselection operation is particularly useful in scenarios such as:

  • Batch Processing: After processing selected records, clear selections to prepare for the next batch
  • User Interface Reset: Provide a "Clear All" button functionality in forms
  • Workflow Management: Reset selections between different workflow steps
  • Data Validation: Clear selections before applying new selection criteria

Working with Individual Occurrences 🎯

While $clearselection clears all selections, you can also work with individual occurrences using occurrence handles:

; Select a specific occurrence
variables handle hOcc endvariables
hOcc = $occhandle("CUSTOMER")
hOcc->$selected = 1  ; Mark as selected

; Check if an occurrence is selected
if (hOcc->$selected)
    ; Do something with selected occurrence
endif

; Clear selection for a single occurrence
hOcc->$selected = 0
Enter fullscreen mode Exit fullscreen mode

Best Practices and Tips πŸ’‘

  • Performance: Use $clearselection instead of looping through occurrences to clear selections individually
  • User Experience: Always provide visual feedback when selections are cleared
  • Error Handling: Check if the entity exists before calling $clearselection
  • Documentation: Comment your code to explain why selections are being cleared

Related Operations πŸ”—

The $clearselection operation works hand-in-hand with other Uniface selection-related features:

  • $selectedoccs: Access the collection of currently selected occurrences
  • $occhandle: Get a handle to work with individual occurrences
  • $selected: The attribute that indicates selection status

Conclusion πŸŽ‰

The $clearselection operation is a simple yet powerful tool for managing entity selections in Uniface 10.4. By understanding how it works with the selection system, developers can create more efficient and user-friendly applications. Whether you're building data entry forms, batch processing systems, or complex workflows, mastering this operation will help you better manage your application's data selection logic.

Remember to combine $clearselection with proper error handling and user feedback to create robust, professional applications that provide a great user experience! πŸš€

Top comments (0)