WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Querying a group was for some reason complicated

Submitted by barnettech on Thu, 09/23/2021 - 11:59

This is working code, as a workaround in using entityquery:

$query = \Drupal::entityQuery('group')
        ->condition('type', 'app_company')
        ->condition('field_netsuite_account_id', $CompanyNSAccountID);
      // Convert to raw SQL as entityQuery->execute is returning invalid
      // results.
      $rawSqlQuery = $query->__toString();

      $connection = \Drupal::database();
      $rawQuery = $connection->query($rawSqlQuery);
      $results = $rawQuery->fetchAssoc();
      // Get the first gid value to load the group.
      $gid = NULL;
      foreach ($results as $result) {
        $gid = $result;
      if($gid != NULL) {
        $group = Group::load($results[$gid]);