Search...
descending( )
Adds a sort to a query, sorting by the specified properties in descending order.
Description
The descending()
function refines a ContactsQueryBuilder
to sort in descending order of
the specified properties. If you specify more than one property,
descending()
sorts the results in descending order by each property in the
order they are listed.
You can sort the following types:
- Number: Sorts numerically.
- Date: Sorts by date and time.
- String: Sorts lexicographically, so
"abc"
comes before"XYZ"
.
If a property contains a number as a String, that value will be sorted alphabetically and not numerically. Items that do not have a value for the specified sort property are ranked lowest.
Syntax
function descending(propertyName: ...string): ContactsQueryBuilder
descending Parameters
NAME
TYPE
DESCRIPTION
propertyName
string
The properties used in the sort.
Supported properties:
_createdDate
lastActivity.activityDate
primaryInfo.email
info.name.first
info.name.last
info.company
info.jobTitle
info.birthdate
Returns
A ContactsQueryBuilder
object that contains the refined query.
Return Type:
Was this helpful?
Add a
descending
sort to a queryCopy Code
1const query = contacts.queryContacts().descending("_createdDate");
Create a query, add a
descending
sort, and run itCopy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { contacts } from 'wix-crm-backend';34export const myQueryContactsFunction = webMethod(Permissions.Anyone, () => {56 return contacts.queryContacts()7 .descending("info.name.last")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;1819 return items;20 } else {21 // Handle case where no matching items found22 }23 })24 .catch((error) => {25 console.error(error);26 })2728});