Search.../

between( )

Refines a query to match items whose specified property value is within a specified range.

Description

The between() function refines a ContactsQueryBuilder to only match items where the value of the specified property is greater than or equal to rangeStart and less than rangeEnd.

It only matches values of the same type. For example, a number value stored as a String type does not match the same number stored as a Number type.

If a property contains a number as a String, that value will be compared alphabetically and not numerically. Items that do not have a value for the specified property are ranked lowest.

The following types of properties can be compared:

  • Number: Compares numerically.
  • Date: Compares JavaScript Date objects.
  • String: Compares lexicographically, so
  • "A" and "M" are between "A" and "Z", but "a", "m", "z" and "Z" are not.
  • "A", "M", "Z", and "a" are between "A" and "z", but "z" is not.

Syntax

function between(propertyName: string, rangeStart: Date, rangeEnd: Date): ContactsQueryBuilder

between Parameters

NAME
TYPE
DESCRIPTION
propertyName
string

The property whose value will be compared to rangeStart and rangeEnd.

Supported properties:

  • _createdDate
  • _updatedDate
  • lastActivity.activityDate
  • info.birthdate
rangeStart
Date

The value to match against.

rangeEnd
Date

The value to match against.

Returns

A ContactsQueryBuilder object that contains the refined query.

Was this helpful?

Add a between filter to a query

Copy Code
1const query = contacts.queryContacts().between("_createdDate", "2020-07-01", "2020-12-31");
Create a query, add a between filter, and run it

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { contacts } from 'wix-crm-backend';
3
4export const myQueryContactsFunction = webMethod(Permissions.Anyone, () => {
5 return contacts.queryContacts()
6 .between("lastActivity.activityDate", "2021-01-01T00:00:00.000", "2021-01-31T11:59:59.000")
7 .find()
8 .then((results) => {
9 if (results.items.length > 0) {
10 const items = results.items;
11 const firstItem = items[0];
12 const pageSize = results.pageSize;
13 const hasNext = results.hasNext();
14 const hasPrev = results.hasPrev();
15 const length = results.length;
16 const query = results.query;
17
18 return items;
19 } else {
20 // Handle case where no matching items found
21 }
22 })
23 .catch((error) => {
24 console.error(error);
25 })
26
27});