Many API endpoints have the ability to filter results based on a search criteria. This can also be used for AutoComplete pick lists where typing filters the pick list results.

Autocomplete Usage: For autocomplete functionality, use the following parameters:

  • x-Search: The user's input text
  • x-SearchField: The field to search in (e.g., "name", "email"). If not specified, Name is typically selected
  • x-SortField: The field to sort by. If brief is enabled, it will add () to the end of the searchfield.
  • x-SortOrder: If sorting is ASC or DESC
  • x-Brief: Returns only ID and search field for minimal payload
  • x-PageLimit: Typically 10-20 for autocomplete dropdowns

Example autocomplete request:

GET /maint/users?search=joh&search_field=name&brief&pagelimit=10

Example response:

    {
      "Data": [
        {"id": 1, "name": "John Doe"},
        {"id": 2, "name": "Johnny Smith"}
      ],
      "Total": 2
    }

JavaScript Debounced AutoComplete Sample Script

   // Debounced autocomplete function
   async function autocomplete(inputValue) {
     if (inputValue.length < 2) return; // Wait for at least 2 characters

      const response = await fetch(
        `/api/db/maint/item?search=${encodeURIComponent(inputValue)}&brief&apiLimit=10`
      );
      const data = await response.json();

      // Display data.data in your autocomplete dropdown
      return data.data;
   }