âšī¸ This blog post was created with AI assistance to help developers understand Uniface better.
đ¤ What is $entname?
The $entname function is a handy ProcScript function in Uniface 10.4 that does two main things:
- đ Returns the name of the current entity you're working with
- đ Checks if a specific entity exists in your component
Think of it as your "Where am I?" tool when navigating through entities in your Uniface application! đ§
đ Basic Syntax
The function is super simple to use:
$entname {( Entity )}
You can use it in two ways:
- Without parameters:
$entname- Gets the current entity name - With parameters:
$entname("CUSTOMER")- Checks if "CUSTOMER" entity exists
đī¸ Parameters and Return Values
| Parameter | Type | Description |
|---|---|---|
| Entity | String | Name of entity to check (optional) |
đ¤ What You Get Back
- No parameter: Current entity name in UPPERCASE, or empty string "" if no current entity
- With parameter: Entity name if it exists, or empty string "" if it doesn't
đĄ Real-World Examples
đ Example 1: Smart Record Creation
This example shows how to create a new record intelligently based on user choice:
trigger create
call AddInsertOcc()
if ($rettype = 65)
creocc $entname, -1 ; Insert before first record
else
creocc $entname, 1 ; Add after last record
endif
end
Here, $entname gives us the current entity name so we can create a new occurrence in the right place! đ¯
đ Example 2: Entity Verification
Sometimes you need to make sure you're working with the right entity:
retrieve ENTITY2
if ($entname = "ENTITY1")
setocc "ENTITY2" ; Switch to the correct entity
endif
This prevents bugs by ensuring you're on the expected entity before doing important operations! đĄī¸
â ī¸ Important Things to Remember
- Case sensitivity: Entity names are returned in UPPERCASE đĸ
- Current entity: The last node in your active path must be a field or entity
- Global ProcScript: Perfect for writing reusable code that works with any entity đ
- Debugging: Super useful when stepping through code in the debugger đ
đ¯ When to Use $entname
This function shines in several scenarios:
- Global ProcScript modules: Makes your code work with any entity
- Dynamic operations: When you need to work with entities determined at runtime
- Debugging sessions: To check which entity you're currently on
- Validation logic: To ensure you're on the correct entity before proceeding
đ§ Where Can You Use It?
Good news! The $entname function works in all component types in Uniface 10.4. Whether you're working with forms, reports, or services, this function has got your back! đĒ
đ Wrapping Up
The $entname function might seem simple, but it's incredibly powerful for:
- Writing flexible, reusable code đ
- Preventing entity-related bugs đĢđ
- Making your debugging sessions more productive đĩī¸
- Creating dynamic, context-aware applications đ
Give it a try in your next Uniface project - you'll be surprised how often it comes in handy! đ
Top comments (0)