> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: queryTasks() # Method package: wixCrmV2 # Method menu location: wixCrmV2 --> tasks --> queryTasks # Method Link: https://dev.wix.com/docs/velo/apis/wix-crm-v2/tasks/query-tasks.md # Method Description: 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()`](/tasks-query-builder/eq),[`ne()`](/tasks-query-builder/ne),[`in()`](/tasks-query-builder/in),[`ascending()`](/tasks-query-builder/ascending),[`descending()`](/tasks-query-builder/descending)| |`_createdDate`|[`eq()`](/tasks-query-builder/eq),[`ne()`](/tasks-query-builder/ne),[`gt()`](/tasks-query-builder/gt),[`lt()`](/tasks-query-builder/lt),[`ge()`](/tasks-query-builder/ge),[`le()`](/tasks-query-builder/le),[`ascending()`](/tasks-query-builder/ascending),[`descending()`](/tasks-query-builder/descending)| |`_updatedDate`|[`eq()`](/tasks-query-builder/eq),[`ne()`](/tasks-query-builder/ne),[`gt()`](/tasks-query-builder/gt),[`lt()`](/tasks-query-builder/lt),[`ge()`](/tasks-query-builder/ge),[`le()`](/tasks-query-builder/le),[`ascending()`](/tasks-query-builder/ascending),[`descending()`](/tasks-query-builder/descending)| |`dueDate`|[`eq()`](/tasks-query-builder/eq),[`ne()`](/tasks-query-builder/ne),[`gt()`](/tasks-query-builder/gt),[`lt()`](/tasks-query-builder/lt),[`ge()`](/tasks-query-builder/ge),[`le()`](/tasks-query-builder/le),[`ascending()`](/tasks-query-builder/ascending),[`descending()`](/tasks-query-builder/descending)| |`status`|[`eq()`](/tasks-query-builder/eq),[`ne()`](/tasks-query-builder/ne),[`in()`](/tasks-query-builder/in)| |`contact.id`|[`eq()`](/tasks-query-builder/eq),[`ne()`](/tasks-query-builder/ne),[`in()`](/tasks-query-builder/in),[`exists()`](/tasks-query-builder/exists)| # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Retrieve all tasks (dashboard page code) ```javascript 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" * } * ] */ ``` ## Retrieve all tasks (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { tasks } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; export const myQueryTasksFunction = webMethod(Permissions.Anyone, async () => { try { const elevatedQueryTasks = elevate(tasks.queryTasks); const queryResults = await elevatedQueryTasks() .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" * } * ] */ ``` ## Retrieve all completed tasks ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { tasks } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; export const queryCompletedTasksFunction = webMethod(Permissions.Anyone, async () => { try { const elevatedQueryTasks = elevate(tasks.queryTasks); const queryResults = await elevatedQueryTasks() .eq("status", "COMPLETED") .ascending("_createdDate") .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": "2", * "title": "Follow up", * "description": "Send a follow up email", * "status": "COMPLETED", * "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-18T14:50:25.210Z" * }, * { * "revision": "2", * "title": "Send email", * "status": "COMPLETED", * "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-18T14:50:29.878Z" * } * ] */ ``` ---