Search.../

startsWith( )

Refines a query to match items whose specified property value starts with a specified string.

Description

The startsWith() function refines a ContactsQueryBuilder to only match items where the value of the specified property starts with a specified string. Matching with startsWith() is case-sensitive, so "TEXT" does not start with "tex".

You can only use startsWith() with a property whose value is a String.

Syntax

function startsWith(propertyName: string, value: string): ContactsQueryBuilder

startsWith Parameters

NAME
TYPE
DESCRIPTION
propertyName
string

The property whose value will be compared with value.

Supported properties:

  • "primaryInfo.email"
  • "primaryInfo.phone"
  • "info.name.first"
  • "info.name.last"
  • "info.emails.email"
  • "info.phones.phone"
  • "info.addresses.street"
  • "info.addresses.city"
  • "info.company"
  • "info.jobTitle"
value
string

The value to match against.

Returns

A ContactsQueryBuilder object that contains the refined query.

Was this helpful?

Add a startsWith filter to a query

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