Creates a query to retrieve a list of tasks.
The queryTasks()
function builds a query to retrieve a list of tasks and returns a TasksQueryBuilder
object.
The returned object contains the query definition which is typically used to run the query using the find()
function. You can refine the query by chaining TasksQueryBuilder
functions onto the query. TasksQueryBuilder
functions enable you to sort, filter, and control the results that queryTasks()
returns.
queryTasks()
runs with these TasksQueryBuilder
defaults, which you can override:
limit(50)
descending('_createdDate')
The functions that are chained to queryTasks()
are applied in the order they are called. For example, if you apply ascending('_createdDate')
and then descending('_updatedDate')
, the results are sorted first by the created date and then, if there are multiple results with the same date, the items are sorted by the updated date.
The following TasksQueryBuilder
functions are supported for queryTasks()
. For a full description of the task
object, see the object returned for the items
property in TasksQueryResult
.
PROPERTY | SUPPORTED FILTERS & SORTING |
---|---|
_id | eq() ,ne() ,in() ,ascending() ,descending() |
_createdDate | eq() ,ne() ,gt() ,lt() ,ge() ,le() ,ascending() ,descending() |
_updatedDate | eq() ,ne() ,gt() ,lt() ,ge() ,le() ,ascending() ,descending() |
dueDate | eq() ,ne() ,gt() ,lt() ,ge() ,le() ,ascending() ,descending() |
status | eq() ,ne() ,in() |
contact.id | eq() ,ne() ,in() ,exists() |
This function requires elevated permissions and runs only on the backend and on dashboard pages.
function queryTasks(): TasksQueryBuilder;
import { tasks } from "wix-crm.v2";
export async function myQueryTasksFunction() {
try {
const queryResults = await tasks.queryTasks().find();
const items = queryResults.items;
const firstItem = items[0];
const pageSize = queryResults.pageSize;
const hasNext = queryResults.hasNext();
const hasPrev = queryResults.hasPrev();
const length = queryResults.length;
const query = queryResults.query;
console.log("Retrieved items:", items);
return items;
} catch (error) {
console.log(error);
// Handle the error
}
}
/* Promise resolves to:
* [
* {
* "revision": "1",
* "title": "Send email",
* "status": "ACTION_NEEDED",
* "source": {
* "sourceType": "APP",
* "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
* },
* "contact": {
* "firstName": "Julie",
* "lastName": "Jones",
* "email": "julie.jones@example.com",
* "phone": "+1 516-569-2772",
* "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
* },
* "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",
* "_createdDate": "2024-01-18T13:47:38.292Z",
* "_updatedDate": "2024-01-18T13:47:38.292Z"
* },
* {
* "revision": "1",
* "title": "Update Contact",
* "description": "Add new label to sontact",
* "dueDate": "2024-03-15T00:00:00.000Z",
* "status": "ACTION_NEEDED",
* "source": {
* "sourceType": "APP",
* "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
* },
* "contact": {
* "firstName": "Julie",
* "lastName": "Jones",
* "email": "julie.jones@example.com",
* "phone": "+1 516-569-2772",
* "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"
* },
* "_id": "cdc52d55-e3e8-4fb4-8413-f15838e352b1",
* "_createdDate": "2024-01-18T13:46:18.198Z",
* "_updatedDate": "2024-01-18T13:46:18.198Z"
* },
* {
* "revision": "1",
* "title": "Follow up",
* "dueDate": "2024-01-26T10:00:00.000Z",
* "status": "ACTION_NEEDED",
* "source": {
* "sourceType": "USER",
* "userId": "162e6672-d392-42f8-bf79-999ee633c92a"
* },
* "contact": {
* "firstName": "Jane",
* "lastName": "Doe",
* "email": "jane.doe1@example.com",
* "phone": "+1 214-533-2543",
* "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"
* },
* "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",
* "_createdDate": "2024-01-18T13:40:56.414Z",
* "_updatedDate": "2024-01-18T13:40:56.414Z"
* },
* {
* "revision": "1",
* "title": "Follow up",
* "description": "Send a follow up email",
* "status": "ACTION_NEEDED",
* "source": {
* "sourceType": "APP",
* "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"
* },
* "contact": {
* "firstName": "Sally",
* "lastName": "Smith",
* "email": "sally.smith@example.com",
* "phone": "+1 524-624-2486",
* "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"
* },
* "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",
* "_createdDate": "2024-01-18T11:35:29.092Z",
* "_updatedDate": "2024-01-18T11:35:29.092Z"
* }
* ]
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.