Search...
countTasks( )
Counts the number of tasks.
Description
This endpoint returns the count of all tasks regardless of the task status
.
Optionally, you can pass a filter to count only tasks based on specified criteria.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function countTasks(options: CountTasksOptions): Promise<CountTasksResponse>
countTasks Parameters
NAME
TYPE
DESCRIPTION
options
Optional
CountTasksOptions
Filtering options.
Returns
Return Type:
Promise<
CountTasksResponse
>NAME
TYPE
DESCRIPTION
count
number
The number of tasks that match the provided filter.
Was this helpful?
Count the total number of tasks (dashboard page code)
Copy Code
1import { tasks } from 'wix-crm.v2';23export async function myCountTasksFunction() {4 try {5 const count = await tasks.countTasks();67 return count;8 } catch(error){9 console.log(error);10 // Handle the error11 }12}1314/* Promise resolves to:15 * {16 * "count": 917 * }18 */
Count the total number of tasks (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45export const myCountTasksFunction = webMethod(Permissions.Anyone, async () => {67 try {8 const elevatedCountTasks = elevate(tasks.countTasks);9 const count = await elevatedCountTasks();1011 return count;12 } catch(error){13 console.log(error);14 // Handle the error15 }16});1718/* Promise resolves to:19 * {20 * "count": 921 * }22 */23
Count the number of completed tasks
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { tasks } from 'wix-crm.v2';3import { elevate } from 'wix-auth';45/* Sample options value:6 * {7 * 'filter' : {8 * 'status': 'COMPLETED'9 * }10 * }11 */1213export const myCountTasksFunction = webMethod(Permissions.Anyone, async (options) => {1415 try {16 const elevatedCountTasks = elevate(tasks.countTasks);17 const count = await elevatedCountTasks(options);1819 return count;20 } catch(error){21 console.log(error);22 // Handle the error23 }24});2526/* Promise resolves to:27 * {28 * "count": 929 * }30 */31