DEV Community

Peter + AI
Peter + AI

Posted on

🎯 Understanding Uniface 10.4's $entname Function: A Developer's Guide

ℹ️ 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 )}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)