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';
2
3export async function myCountTasksFunction() {
4 try {
5 const count = await tasks.countTasks();
6
7 return count;
8 } catch(error){
9 console.log(error);
10 // Handle the error
11 }
12}
13
14/* Promise resolves to:
15 * {
16 * "count": 9
17 * }
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';
4
5export const myCountTasksFunction = webMethod(Permissions.Anyone, async () => {
6
7 try {
8 const elevatedCountTasks = elevate(tasks.countTasks);
9 const count = await elevatedCountTasks();
10
11 return count;
12 } catch(error){
13 console.log(error);
14 // Handle the error
15 }
16});
17
18/* Promise resolves to:
19 * {
20 * "count": 9
21 * }
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';
4
5/* Sample options value:
6 * {
7 * 'filter' : {
8 * 'status': 'COMPLETED'
9 * }
10 * }
11 */
12
13export const myCountTasksFunction = webMethod(Permissions.Anyone, async (options) => {
14
15 try {
16 const elevatedCountTasks = elevate(tasks.countTasks);
17 const count = await elevatedCountTasks(options);
18
19 return count;
20 } catch(error){
21 console.log(error);
22 // Handle the error
23 }
24});
25
26/* Promise resolves to:
27 * {
28 * "count": 9
29 * }
30 */
31