Search.../

or( )

Adds an or condition to the query.

Description

The or() function adds an inclusive or condition to a ContactsQueryBuilder. A query with an or returns all the items that match the query as defined up to the or function, the items that match the query passed to the or function, and the items that match both.

The or() function is designed to work with 2 or more queries. If you use it on its own, it will return all the items that meet the query criteria.

Syntax

function or(query: ContactsQueryBuilder): ContactsQueryBuilder

or Parameters

NAME
TYPE
DESCRIPTION
query

A query to add to the initial query as an or condition.

Returns

A ContactsQueryBuilder object that contains the refined query.

Was this helpful?

Add an or filter to a query

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 .eq("info.addresses.country", "GB")
7 .or(contacts.queryContacts()
8 .eq("info.addresses.country", "FR"))
9 .find()
10 .then((results) => {
11 if (results.items.length > 0) {
12 const items = results.items;
13 const firstItem = items[0];
14 const pageSize = results.pageSize;
15 const hasNext = results.hasNext();
16 const hasPrev = results.hasPrev();
17 const length = results.length;
18 const query = results.query;
19
20 return items;
21 } else {
22 // Handle case where no matching items found
23 }
24 })
25 .catch((error) => {
26 console.error(error);
27 })
28
29});
Create a query, add an or 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 .eq("info.addresses.country", "GB")
7 .or(contacts.queryContacts()
8 .eq("info.addresses.country", "FR"))
9 .find()
10 .then((results) => {
11 if (results.items.length > 0) {
12 const items = results.items;
13 const firstItem = items[0];
14 const pageSize = results.pageSize;
15 const hasNext = results.hasNext();
16 const hasPrev = results.hasPrev();
17 const length = results.length;
18 const query = results.query;
19
20 return items;
21 } else {
22 // Handle case where no matching items found
23 }
24 })
25 .catch((error) => {
26 console.error(error);
27 })
28
29});