CorvidReference

tasks

The Tasks API is used to manage a site's tasks.

Use tasks to organize and prioritize your work with Ascend by Wix.

To use the Tasks API, import wixCrm from the wix-crm-backend module:

   import wixCrm from 'wix-crm-backend';

Table of Contents

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
TaskAn object representing a task.
TaskInfoAn object representing information for creating or updating a task.

completeTask( )

Sets a task as completed.

Description

The completeTask() function returns a Promise that resolves to the ID of the the task after it is set as completed.

Syntax

function completeTask(taskId: string): Promise<string>
PARAMETERS
?
Values that you pass to a function.
taskId
string
ID of the task to set as complete.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - ID of the task to set as complete.

Examples

Set a task as completed

import wixCrm from 'wix-crm-backend';

export function completeTask(taskId) {
  return wixCrm.tasks.completeTask(taskId);
}

// Returns a promise that resolves to:
// "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"

createTask( )

Creates a new task.

Description

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>
PARAMETERS
?
Values that you pass to a function.
taskInfo
The information to use when creating the task.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - ID of the newly created task.

Examples

Create a new task

import wixCrm from 'wix-crm-backend';

export function createTask(title, contactId, dueDate) {
  const taskInfo = {
    "title": title,
    "contactId": contactId,
    "dueDate": dueDate
  };

  return wixCrm.tasks.createTask(taskInfo);
}

// Returns promise that resolves to:
// 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.

/****************************
 * backend code - tasks.jsw *
 ****************************/
import wixCrm from 'wix-crm-backend';
import wixUsers from 'wix-users-backend';

export function createFollowUpTask() {
  let followUpDate = new Date();
  followUpDate.setMonth(followUpDate.getMonth() + 1);

  const taskInfo = {
    "title": "Follow Up",
    "contactId": wixUsers.currentUser.id,
    "dueDate": followUpDate
  };

  return wixCrm.tasks.createTask(taskInfo);
}

/*************
 * page code *
 *************/
import {createFollowUpTask} from 'backend/tasks';

// ..

export function followUpButton_click(event) {
  createFollowUpTask()
    .then( (result) => {
      console.log(result); // "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"
    } )
    .catch( (error) => {
      console.log(error);
    } );
}

getTask( )

Gets a task by ID.

Description

The getTask() function returns a Promise that resolves to the task with the given ID.

Syntax

function getTask(taskId: string): Promise<Task>
PARAMETERS
?
Values that you pass to a function.
taskId
string
The ID of the task to get from the task list.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Task>
Fulfilled - The task with the given ID.

Examples

Get a task by ID

import wixCrm from 'wix-crm-backend';

export function getTask(taskId) {
  return wixCrm.tasks.getTask(taskId);
}

/* Returns a promise that resolves to:
 * {
 *   "_id": "6cb91509-7aa1-479b-a242-7327f58b7157",
 *   "title": "Add domain",
 *   "version": 9,
 *   "dueDate": "2019-01-22T10:00:00Z",
 *   "contactId": "6cb91509-7aa1-479b-a242-7327f58b7157",
 *   "isCompleted": false,
 *   "applicationId: "791f5e4f-5377-47a9-bd8e-cc0ef4605c8f",
 *   "creatorType": "APP"
 * }
 */

removeTask( )

Removes an existing task.

Description

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

Syntax

function removeTask(taskId: string): Promise<string>
PARAMETERS
?
Values that you pass to a function.
taskId
string
ID of the task to remove.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - ID of the removed task.

Examples

Remove a task

import wixCrm from 'wix-crm-backend';

export function removeTask(taskId) {
  return wixCrm.tasks.removeTask(taskId);
}

// 3c9683ea-f6cc-470b-b0d1-2eb6b8cea912 - removed task id

resetTask( )

Resets a task as not completed.

Description

The resetTask() function returns a Promise that resolves to the ID of the the task after it is reset as not completed.

Syntax

function resetTask(taskId: string): Promise<string>
PARAMETERS
?
Values that you pass to a function.
taskId
string
ID of the task to reset.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - ID of the task to set as not completed.

Examples

Reset a task as not completed

import wixCrm from 'wix-crm-backend';

export function resetTask(taskId) {
  return wixCrm.tasks.resetTask(taskId);
}

// Returns a promise that resolves to:
// "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"

updateTaskFields( )

Updates the specified fields of an existing task.

Description

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

Only the properties passed in the TaskInfo object will be updated. All other properties will remain the same.

To remove a value from the task, pass its corresponding property with a value of null.

Syntax

function updateTaskFields(taskId: string, taskInfo: TaskInfo): Promise<string>
PARAMETERS
?
Values that you pass to a function.
taskId
string
ID of the task to update.
taskInfo
The information to update the task with.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - ID of the updated task.

Examples

Update a task

import wixCrm from 'wix-crm-backend';

export function updateTaskFields(taskId, taskInfo) {
  return wixCrm.tasks.updateTaskFields(taskId, taskInfo);
}

// Returns a promise that resolves to:
// "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"

Update some of a task's info

This example demonstrates how to update only the due date of a given task to a month from today, while leaving the rest of the task's information as it was before the update.

import wixCrm from 'wix-crm-backend';

export function updateTaskOneMonth(taskId) {
  let date = new Date();
  date.setMonth(date.getMonth() + 1);

  const taskInfo = {
    "dueDate": date
  };

  return wixCrm.tasks.updateTaskFields(taskId, taskInfo);
}

// Returns a promise that resolves to:
// "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"

Update some of a task's info and delete some info

This example demonstrates how to delete a task's due date and contact information, while updating its title.

import wixCrm from 'wix-crm-backend';

export function updateTitle(taskId, newTitle) {
  const taskInfo = {
    "title": newTitle,
    "dueDate": null,
    "contactId": null
  };

  return wixCrm.tasks.updateTaskFields(taskId, taskInfo);
}

// Returns a promise that resolves to:
// "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"

Task

An object representing a task.

See Also

getTask()

Syntax

type Task = {
  title: string
  isCompleted: boolean
  contactId: string
  version: number
  _id: string
  dueDate: Date
  creatorType: string
  userId: string
  applicationId: string
}
MEMBERS
?
The properties of an object.
title
string
Task title.
isCompleted
boolean

Indicates whether the task has been completed.

contactId
string

Unique identifier of the site contact that this task is linked to.

version
number

Running task version number. Each time an action is performed on a task its version number is incremented.

_id
string
Unique task identifier.
dueDate
Date
Date the task is due.
creatorType
string

Type of the task's creator. "USER" if the task was created using the site's dashboard. "APP" if the task was created using the createTask() function or if it was created by an app installed on the site.

userId(Optional)
string

When creatorType is "USER", the unique identifier of the user that created the task in the dashboard. Otherwise, userId is not present.

applicationId(Optional)
string

When creatorType is "APP", the unique identifier of the application that created the task. Otherwise, applicationId is not present.

Examples

Get a task by ID

import wixCrm from 'wix-crm-backend';

export function getTask(taskId) {
  return wixCrm.tasks.getTask(taskId);
}

/* Returns a promise that resolves to:
 * {
 *   "_id": "6cb91509-7aa1-479b-a242-7327f58b7157",
 *   "title": "Add domain",
 *   "version": 9,
 *   "dueDate": "2019-01-22T10:00:00Z",
 *   "contactId": "6cb91509-7aa1-479b-a242-7327f58b7157",
 *   "isCompleted": false,
 *   "applicationId: "791f5e4f-5377-47a9-bd8e-cc0ef4605c8f",
 *   "creatorType": "APP"
 * }
 */

TaskInfo

An object representing information for creating or updating a task.

See Also

createTask()

Syntax

type TaskInfo = {
  title: string
  dueDate: Date
  contactId: string
}
MEMBERS
?
The properties of an object.
title(Optional)
string
Task title.
dueDate(Optional)
Date
Date the task is due.
contactId(Optional)
string

Unique identifier of the site contact that this task is linked to.

Examples

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.

/****************************
 * backend code - tasks.jsw *
 ****************************/
import wixCrm from 'wix-crm-backend';
import wixUsers from 'wix-users-backend';

export function createFollowUpTask() {
  let followUpDate = new Date();
  followUpDate.setMonth(followUpDate.getMonth() + 1);

  const taskInfo = {
    "title": "Follow Up",
    "contactId": wixUsers.currentUser.id,
    "dueDate": followUpDate
  };

  return wixCrm.tasks.createTask(taskInfo);
}

/*************
 * page code *
 *************/
import {createFollowUpTask} from 'backend/tasks';

// ..

export function followUpButton_click(event) {
  createFollowUpTask()
    .then( (result) => {
      console.log(result); // "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"
    } )
    .catch( (error) => {
      console.log(error);
    } );
}