βΉοΈ 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)