queryTasks( )
Creates a query to retrieve a list of tasks.
Description
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 to run. This function is not universal and runs only on the backend.
Syntax
function queryTasks(): TasksQueryBuilder
queryTasks Parameters
This function does not take any parameters.
Returns
Return Type:
Was this helpful?
1import { tasks } from 'wix-crm.v2';23export async function myQueryTasksFunction() {45 try {6 const queryResults = await tasks.queryTasks()7 .find();89 const items = queryResults.items;10 const firstItem = items[0];11 const pageSize = queryResults.pageSize;12 const hasNext = queryResults.hasNext();13 const hasPrev = queryResults.hasPrev();14 const length = queryResults.length;15 const query = queryResults.query;16 console.log('Retrieved items:', items);1718 return items;19 } catch (error) {20 console.log(error);21 // Handle the error22 }23}2425/* Promise resolves to:26 * [27 * {28 * "revision": "1",29 * "title": "Send email",30 * "status": "ACTION_NEEDED",31 * "source": {32 * "sourceType": "APP",33 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"34 * },35 * "contact": {36 * "firstName": "Julie",37 * "lastName": "Jones",38 * "email": "julie.jones@example.com",39 * "phone": "+1 516-569-2772",40 * "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"41 * },42 * "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",43 * "_createdDate": "2024-01-18T13:47:38.292Z",44 * "_updatedDate": "2024-01-18T13:47:38.292Z"45 * },46 * {47 * "revision": "1",48 * "title": "Update Contact",49 * "description": "Add new label to sontact",50 * "dueDate": "2024-03-15T00:00:00.000Z",51 * "status": "ACTION_NEEDED",52 * "source": {53 * "sourceType": "APP",54 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"55 * },56 * "contact": {57 * "firstName": "Julie",58 * "lastName": "Jones",59 * "email": "julie.jones@example.com",60 * "phone": "+1 516-569-2772",61 * "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"62 * },63 * "_id": "cdc52d55-e3e8-4fb4-8413-f15838e352b1",64 * "_createdDate": "2024-01-18T13:46:18.198Z",65 * "_updatedDate": "2024-01-18T13:46:18.198Z"66 * },67 * {68 * "revision": "1",69 * "title": "Follow up",70 * "dueDate": "2024-01-26T10:00:00.000Z",71 * "status": "ACTION_NEEDED",72 * "source": {73 * "sourceType": "USER",74 * "userId": "162e6672-d392-42f8-bf79-999ee633c92a"75 * },76 * "contact": {77 * "firstName": "Jane",78 * "lastName": "Doe",79 * "email": "jane.doe1@example.com",80 * "phone": "+1 214-533-2543",81 * "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"82 * },83 * "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",84 * "_createdDate": "2024-01-18T13:40:56.414Z",85 * "_updatedDate": "2024-01-18T13:40:56.414Z"86 * },87 * {88 * "revision": "1",89 * "title": "Follow up",90 * "description": "Send a follow up email",91 * "status": "ACTION_NEEDED",92 * "source": {93 * "sourceType": "APP",94 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"95 * },96 * "contact": {97 * "firstName": "Sally",98 * "lastName": "Smith",99 * "email": "sally.smith@example.com",100 * "phone": "+1 524-624-2486",101 * "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"102 * },103 * "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",104 * "_createdDate": "2024-01-18T11:35:29.092Z",105 * "_updatedDate": "2024-01-18T11:35:29.092Z"106 * }107 * ]108 */
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45export const myQueryTasksFunction = webMethod(Permissions.Anyone, async () => {6 try {7 const elevatedQueryTasks = elevate(tasks.queryTasks);8 const queryResults = await elevatedQueryTasks()9 .find();1011 const items = queryResults.items;12 const firstItem = items[0];13 const pageSize = queryResults.pageSize;14 const hasNext = queryResults.hasNext();15 const hasPrev = queryResults.hasPrev();16 const length = queryResults.length;17 const query = queryResults.query;18 console.log('Retrieved items:', items);1920 return items;21 } catch (error) {22 console.log(error);23 // Handle the error24 }25});2627/* Promise resolves to:28 * [29 * {30 * "revision": "1",31 * "title": "Send email",32 * "status": "ACTION_NEEDED",33 * "source": {34 * "sourceType": "APP",35 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"36 * },37 * "contact": {38 * "firstName": "Julie",39 * "lastName": "Jones",40 * "email": "julie.jones@example.com",41 * "phone": "+1 516-569-2772",42 * "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"43 * },44 * "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",45 * "_createdDate": "2024-01-18T13:47:38.292Z",46 * "_updatedDate": "2024-01-18T13:47:38.292Z"47 * },48 * {49 * "revision": "1",50 * "title": "Update Contact",51 * "description": "Add new label to sontact",52 * "dueDate": "2024-03-15T00:00:00.000Z",53 * "status": "ACTION_NEEDED",54 * "source": {55 * "sourceType": "APP",56 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"57 * },58 * "contact": {59 * "firstName": "Julie",60 * "lastName": "Jones",61 * "email": "julie.jones@example.com",62 * "phone": "+1 516-569-2772",63 * "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"64 * },65 * "_id": "cdc52d55-e3e8-4fb4-8413-f15838e352b1",66 * "_createdDate": "2024-01-18T13:46:18.198Z",67 * "_updatedDate": "2024-01-18T13:46:18.198Z"68 * },69 * {70 * "revision": "1",71 * "title": "Follow up",72 * "dueDate": "2024-01-26T10:00:00.000Z",73 * "status": "ACTION_NEEDED",74 * "source": {75 * "sourceType": "USER",76 * "userId": "162e6672-d392-42f8-bf79-999ee633c92a"77 * },78 * "contact": {79 * "firstName": "Jane",80 * "lastName": "Doe",81 * "email": "jane.doe1@example.com",82 * "phone": "+1 214-533-2543",83 * "_id": "dfcb4c01-7336-4b59-ae43-957cb89952ce"84 * },85 * "_id": "3a49f901-62d5-4ca2-a8e8-395c562a3f7b",86 * "_createdDate": "2024-01-18T13:40:56.414Z",87 * "_updatedDate": "2024-01-18T13:40:56.414Z"88 * },89 * {90 * "revision": "1",91 * "title": "Follow up",92 * "description": "Send a follow up email",93 * "status": "ACTION_NEEDED",94 * "source": {95 * "sourceType": "APP",96 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"97 * },98 * "contact": {99 * "firstName": "Sally",100 * "lastName": "Smith",101 * "email": "sally.smith@example.com",102 * "phone": "+1 524-624-2486",103 * "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"104 * },105 * "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",106 * "_createdDate": "2024-01-18T11:35:29.092Z",107 * "_updatedDate": "2024-01-18T11:35:29.092Z"108 * }109 * ]110 */111
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45export const queryCompletedTasksFunction = webMethod(Permissions.Anyone, async () => {6 try {7 const elevatedQueryTasks = elevate(tasks.queryTasks);8 const queryResults = await elevatedQueryTasks()9 .eq("status", "COMPLETED")10 .ascending("_createdDate")11 .find();1213 const items = queryResults.items;14 const firstItem = items[0];15 const pageSize = queryResults.pageSize;16 const hasNext = queryResults.hasNext();17 const hasPrev = queryResults.hasPrev();18 const length = queryResults.length;19 const query = queryResults.query;20 console.log('Retrieved items:', items);2122 return items;23 } catch (error) {24 console.log(error);25 // Handle the error26 }27});2829/* Promise resolves to:30* [31 * {32 * "revision": "2",33 * "title": "Follow up",34 * "description": "Send a follow up email",35 * "status": "COMPLETED",36 * "source": {37 * "sourceType": "APP",38 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"39 * },40 * "contact": {41 * "firstName": "Sally",42 * "lastName": "Smith",43 * "email": "sally.smith@example.com",44 * "phone": "+1 524-624-2486",45 * "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc"46 * },47 * "_id": "3194f3f2-945f-4810-8905-d02b24f9e790",48 * "_createdDate": "2024-01-18T11:35:29.092Z",49 * "_updatedDate": "2024-01-18T14:50:25.210Z"50 * },51 * {52 * "revision": "2",53 * "title": "Send email",54 * "status": "COMPLETED",55 * "source": {56 * "sourceType": "APP",57 * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a"58 * },59 * "contact": {60 * "firstName": "Julie",61 * "lastName": "Jones",62 * "email": "julie.jones@example.com",63 * "phone": "+1 516-569-2772",64 * "_id": "719784da-0361-4f86-b4a4-b38409d7bce1"65 * },66 * "_id": "37e5d602-adad-4ba3-ba3d-06384394fb9e",67 * "_createdDate": "2024-01-18T13:47:38.292Z",68 * "_updatedDate": "2024-01-18T14:50:29.878Z"69 * }70 * ]71 */72