Announcement

Collapse
No announcement yet.

Search for phone number with numeric values only.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Search for phone number with numeric values only.

    In ESPO 6.1.0 and below I had this code under the actionList() controller method, which would replace the phoneNumber search attribute with phoneNumberNumeric attribute such that the ORM would query with just the numbers in the DB and find the entities.
    Code:
    if ($params['where'] != null) {
      $whereCount = 0;
      foreach ($params['where'] as $where) {
        if (isset($where['attribute'])) {
          if ($where['attribute'] == 'phoneNumber') {
            $newWhere = [
            'attribute' => 'phoneNumberNumeric',
            'type' => $where['type'],
            'value' => preg_replace('/[^0-9]/', '', $where['value']),
          ];
          $params['where'][$whereCount] = $newWhere;
        }
        ++$whereCount;
        }
      }
    }
    But since 7.0 I can no longer do this as fetchListParamsFromRequest method no longer exists.

    How do I go about searching for entities (from list view search filters) with just the numeric phone number values?

    telecastg item​​​​​​​ Any clue?

  • #2
    It's possible to have a custom converter of the where item for a specific field. https://docs.espocrm.com/development...erclassnamemap

    Keys to define:

    phoneNumber_equals
    phoneNumber_like

    Comment


    • #3
      Thanks Yuri this works.

      This is how I did it.

      Created a Lead.json file under custom\Espo\Custom\Resources\metadata\selectDefs and added this:
      Code:
      {
        "whereItemConverterClassNameMap": {
          "phoneNumber_equals": "Espo\\Custom\\Classes\\Select\\PhoneNumber\\ItemConverters\\Equals",
        }
      }
      Created a Equals.php class under custom\Espo\Custom\Classes\Select\PhoneNumber\Item Converters with the following code:
      Code:
      class Equals implements ItemConverter
      {
        public function convert(QueryBuilder $queryBuilder, Item $item): WhereClauseItem
        {
          $value = $item->getValue();
          return WhereClause::fromRaw([
            'phoneNumberNumeric' => $value,
          ]);
        }
      }
      Clear Cache. Rebuild.

      Hope this helps someone.

      Comment


      • #4
        We use simple trick:


        In entityDefs:

        Code:
        {
        "collection": {
        "textFilterFields": [
        "__APPEND__",
        "phoneNumberNumeric"
        ]
        }
        }

        Comment

        Working...
        X