Autocompletion of existing contacts broken for many display fields

Created on 25 June 2024, 3 months ago
Updated 2 July 2024, 3 months ago

Problem/Motivation

For many display fields, autocompletion of existing contacts is broken. This includes Current Employer, Email, City, District/County, State/Province, Country, Postal Code, and Phone. If any of these are part of the selected display fields, the autocompletion throws an error.

The exact rules when an error is thrown seem to depend on whether the user is anonymous or not and whether only display fields as stated above are selected:

  • anonymous user: always getting an error
  • non-anonymous user & only selecting fields stated above: getting an error
  • non-anonymous user & also selecting fields not stated above: not getting an error

Detailed steps to reproduce

Create a new webform, then:

Add existing contact

  1. Go to CiviCRM
  2. Check Enable CiviCRM Processing
  3. Number of Contacts: 1
  4. Under 1. Contact 1Contact Fields Make sure that Existing Contact is checked
  5. Click Save Settings

Display city for existing contact

  1. Go to Build
  2. Edit Existing Contact
  3. Set Form displayForm Widget to Autocomplete
  4. At Form displayContact Display Field(s) select Display Name and City
  5. Click Save

Make form available

  1. Go to Settings
  2. Set URL path settingsWebform URL alias, e.g., to /test
  3. Click Save

Fill form and notice error

  1. As anonymous user, navigate to the form (e.g., at /test)
  2. Start typing into field Existing Contact
  3. Notice HTTP 500 in browser console

In Drupal's error log, the following error of type php can be found:

CRM_Core_Exception: Invalid field 'address.city' in Civi\Api4\Query\Api4SelectQuery->getField() (line 400 of /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4SelectQuery.php).

Backtrace:

#0 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(168): Civi\Api4\Query\Api4SelectQuery->getField()
#1 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(246): Civi\Api4\Query\Api4Query->getExpression()
#2 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(215): Civi\Api4\Query\Api4Query->composeClause()
#3 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(201): Civi\Api4\Query\Api4Query->treeWalkClauses()
#4 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4SelectQuery.php(230): Civi\Api4\Query\Api4Query->treeWalkClauses()
#5 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(80): Civi\Api4\Query\Api4SelectQuery->buildWhereClause()
#6 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4Query.php(90): Civi\Api4\Query\Api4Query->getSql()
#7 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Query/Api4SelectQuery.php(106): Civi\Api4\Query\Api4Query->getResults()
#8 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Generic/DAOGetAction.php(107): Civi\Api4\Query\Api4SelectQuery->run()
#9 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Generic/DAOGetAction.php(94): Civi\Api4\Generic\DAOGetAction->getObjects()
#10 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Provider/ActionObjectProvider.php(70): Civi\Api4\Generic\DAOGetAction->_run()
#11 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/API/Kernel.php(156): Civi\Api4\Provider\ActionObjectProvider->invoke()
#12 /var/www/[HOST]/vendor/civicrm/civicrm-core/Civi/Api4/Generic/AbstractAction.php(256): Civi\API\Kernel->runRequest()
#13 /var/www/[HOST]/vendor/civicrm/civicrm-core/api/api.php(91): Civi\Api4\Generic\AbstractAction->execute()
#14 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/Utils.php(634): civicrm_api4()
#15 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/ContactComponent.php(154): Drupal\webform_civicrm\Utils->wf_civicrm_api4()
#16 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/WebformAjax.php(85): Drupal\webform_civicrm\ContactComponent->wf_crm_contact_search()
#17 /var/www/[HOST]/web/modules/contrib/webform_civicrm/src/Controller/AjaxController.php(53): Drupal\webform_civicrm\WebformAjax->contactAjax()
#18 [internal function]: Drupal\webform_civicrm\Controller\AjaxController->handle()
#19 /var/www/[HOST]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#20 /var/www/[HOST]/web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#21 /var/www/[HOST]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext()
#22 /var/www/[HOST]/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#23 /var/www/[HOST]/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#24 /var/www/[HOST]/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#25 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#26 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#27 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#28 /var/www/[HOST]/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#29 /var/www/[HOST]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(191): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#30 /var/www/[HOST]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(128): Drupal\page_cache\StackMiddleware\PageCache->fetch()
#31 /var/www/[HOST]/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(82): Drupal\page_cache\StackMiddleware\PageCache->lookup()
#32 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
#33 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#34 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#35 /var/www/[HOST]/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#36 /var/www/[HOST]/web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#37 /var/www/[HOST]/web/index.php(19): Drupal\Core\DrupalKernel->handle()
#38 {main}
🐛 Bug report
Status

Active

Version

6.2

Component

Webform/Drupal

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @fkohrt
  • 🇮🇳India jitendrapurohit

    Sounds like a permission issue, does anonymous have access to see all contacts? If no and still you want to display all contacts in the `Existing Contact` field, perhaps try disabling `Enforce Permissions` checkbox on `Existing Contact` element.

  • Thanks for replying!

    Allowing CiviCRM: view all contacts for anonymous users didn't have any effect for me at all in this regard.

    Unchecking Enforce Permissions indeed resolves the issue if one also selects fields not stated above. This still feels like a bug because according to an ACL I set up, some contacts should be viewable by everyone even with permissions enforced (and searching for them indeed works if none of the fields stated above are selected). So why should selecting some additional fields make the difference?

    Also, if I only select display fields stated above (e.g., only City), unchecking Enforce Permissions still doesn't make it work, not even for administrators.

    So, I'm really unsure as to whether everything works as designed – but maybe I just haven't figured out why it works this way.

Production build 0.71.5 2024