Search.../

createTask( )

Deprecated. This function will continue to work, but a newer version is available at wix-crm.v2.Tasks.createTask().

Description

Migration Instructions

If this function is already in your code, it will continue to work. To stay compatible with future changes, migrate to wix-crm.v2.Tasks.createTask().

To migrate to the new function:

  1. Add the new import statement:

    import { tasks } from 'wix-crm.v2'
    javascript | Copy Code
  2. If you plan to migrate all functions that use wixCrmBackend, remove the original import wixCrmBackend statement.

  3. Look for any code that uses wixCrmBackend.tasks.createTask(), and replace it with with tasks.createTask(). Update your code to work with the new createTask() call and response properties.

  4. Test your changes to make sure your code behaves as expected.

Creates a new task.

The createTask() function returns a Promise that resolves to the ID of the the newly created task after it has been successfully created.

When creating a new task, the specified TaskInfo object must contain a title value.

Syntax

function createTask(taskInfo: TaskInfo): Promise<string>

createTask Parameters

NAME
TYPE
DESCRIPTION
taskInfo
TaskInfo

The information to use when creating the task.

Returns

Fulfilled - ID of the newly created task.

Return Type:

Promise<string>

Was this helpful?

Create a new task

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { tasks } from 'wix-crm-backend';
3
4export const createTask = webMethod(Permissions.Anyone, (title, contactId, dueDate) => {
5 const taskInfo = {
6 "title": title,
7 "contactId": contactId,
8 "dueDate": dueDate
9 };
10
11 return tasks.createTask(taskInfo);
12});
13
14// Returns promise that resolves to:
15// 3c9683ea-f6cc-470b-b0d1-2eb6b8cea912
Create a new task on button click

This example demonstrates how to create a task to follow up with the current user in a month's time when the user clicks a Follow Up button.

Copy Code
1/****************************
2 * Backend code - tasks.web.js *
3 ****************************/
4import { Permissions, webMethod } from 'wix-web-module';
5import { tasks } from 'wix-crm-backend';
6import wixUsers from 'wix-users-backend';
7
8export const createFollowUpTask = webMethod(Permissions.Anyone, () => {
9 let followUpDate = new Date();
10 followUpDate.setMonth(followUpDate.getMonth() + 1);
11
12 const taskInfo = {
13 "title": "Follow Up",
14 "contactId": wixUsers.currentUser.id,
15 "dueDate": followUpDate
16 };
17
18 return tasks.createTask(taskInfo);
19});
20
21/*************
22 * page code *
23 *************/
24import { createFollowUpTask } from 'backend/tasks.web';
25
26// ..
27
28export function followUpButton_click(event) {
29 createFollowUpTask()
30 .then((result) => {
31 console.log(result); // "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"
32 })
33 .catch((error) => {
34 console.log(error);
35 });
36}