Skip to content

KVSKBAUserManagement#

Procedures#

LookupUserID(Code[50]) : Boolean#

Summary: Opens a user lookup dialog and returns the selected user name.

procedure LookupUserID(var UserName: Code[50]): Boolean

Parameters:

  • UserName: Variable containing the initial user name and receiving the selected user name.

Returns: True if a user was selected; otherwise false.

Remarks: This procedure provides a simplified user lookup interface that only returns the user name. It internally calls the LookupUser procedure to display the Users page and retrieve the selection.

         **Process Flow:**
         1. Calls internal LookupUser procedure with UserName parameter
         2. User selects from Users page (Page::Users)
         3. Returns selected user name via var parameter
         4. Returns true if user confirmed selection (LookupOK), false if cancelled

         **Use Cases:**
         - User selection in fields that only need the user name
         - Simple user lookup without requiring User Security ID
         - Validation dialogs where user must be selected
         - Assignment workflows requiring user name only

         **Input/Output:**
         - Input: UserName can be pre-filled to position the cursor in the lookup
         - Output: UserName contains the selected user's "User Name" field
         - Return value: true = user selected, false = cancelled

         **Page Interaction:**
         - Opens Users page (Page::Users) in modal mode
         - Uses Page.RunModal with LookupOK action check
         - Positions on user matching initial UserName (if exists)

         **Related Procedures:**
         - LookupUser: Extended version that also returns User Security ID
         - ValidateUserID: Validates that a user name exists

         **Example Usage:**
         ```al
         var
             UserName: Code[50];
         begin
             if UserManagement.LookupUserID(UserName) then
                 Message('Selected user: %1', UserName);
         end;
         ```

ValidateUserID(Code[50]) :#

Summary: Validates that a user name exists in the system.

procedure ValidateUserID(UserName: Code[50]): 

Parameters:

  • UserName: The user name to validate.

Remarks: This procedure verifies that a given user name corresponds to an existing user in the User table. If the user name is not found and users exist in the system, an error is raised.

         **Validation Logic:**

         1. **Empty User Name:**
            - If UserName is empty (''), validation passes silently
            - No error is raised for blank values
            - Allows optional user fields to remain empty

         2. **User Name Lookup:**
            - Sets current key to "User Name" for efficient search
            - Filters User table to exact match on user name
            - Attempts to find the first matching record

         3. **User Not Found:**
            - Resets filters on User table
            - Checks if ANY users exist in the system (IsEmpty)
            - If users exist: Raises error with message "User name %1 does not exist."
            - If no users exist: Validation passes (empty system scenario)

         4. **User Found:**
            - Validation passes silently
            - No action taken

         **Error Behavior:**
         - Error Message: "User name %1 does not exist." (localized)
         - Error is raised via Error() function (stops execution)
         - Only raised if user not found AND other users exist

         **Special Cases:**
         - Empty user name: Always valid (no error)
         - Empty user table: Always valid (no error even for non-existent names)
         - Non-existent user with populated user table: Error raised

         **Use Cases:**
         - Field validation on user assignment fields
         - OnValidate triggers for user-related fields
         - Data integrity checks before processing
         - Import validation for user-related data
         - Pre-processing validation in batch operations

         **Empty System Handling:**
         The check for IsEmpty prevents errors in brand-new systems or test environments
         where the User table might not yet be populated. This avoids blocking data entry
         in setup scenarios.

         **Integration Points:**
         - Typically called from table field validation (OnValidate trigger)
         - Can be used in codeunits before user-dependent operations
         - Useful in data migration or import scenarios

         **Related Procedures:**
         - LookupUserID: Provides user selection dialog
         - LookupUser: Extended user lookup with Security ID

         **Example Usage:**
         ```al
         // In a table field OnValidate trigger:
         trigger OnValidate()
         var
             UserManagement: Codeunit KVSKBAUserManagement;
         begin
             UserManagement.ValidateUserID("Assigned User ID");
         end;
         ```

         **Performance Considerations:**
         - Uses indexed search with SetCurrentKey("User Name")
         - FindFirst stops at first match (efficient)
         - IsEmpty check is fast (no record retrieval)