> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: createTask(task: Task) # Method package: wixCrmV2 # Method menu location: wixCrmV2 --> tasks --> createTask # Method Link: https://dev.wix.com/docs/velo/apis/wix-crm-v2/tasks/create-task.md # Method Description: Creates a new task. All fields in the `task` object are optional. If you don't pass any fields in the `task` object, the function returns a task with the following core properties: - `_id` - `_createdDate` - `_updatedDate` - `status` - `source` - `revision` # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Create a new task (dashboard page code) ```javascript import { tasks } from 'wix-crm.v2'; /* Sample task value: * { * contact: { * _id: '5518ee7f-270e-40c4-b756-dad56e8f0ffc' * }, * description: 'Send a follow up email', * dueDate: new Date(2024, 1, 31), * status: 'ACTION_NEEDED', * title: 'Follow up' * } */ export async function myCreateTaskFunction(task) { try { const newTask = await tasks.createTask(task); console.log('Successfully created a new task:', newTask); return newTask; } catch(error){ console.log(error); // Handle the error } } /* Promise resolves to: * { * "revision": "1", * "title": "Follow up", * "description": "Send a follow up email", * "dueDate": "2024-01-31T00:00:00.000Z", * "status": "ACTION_NEEDED", * "source": { * "sourceType": "APP", * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a" * }, * "contact": { * "firstName": "Sally", * "lastName": "Smith", * "email": "sally.smith@example.com", * "phone": "+1 524-624-2486", * "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc" * }, * "_id": "37c2c378-8085-4ef7-8a3e-6f341248e757", * "_createdDate": "2024-01-18T12:16:37.452Z", * "_updatedDate": "2024-01-18T12:16:37.452Z" * } */ ``` ## Create a new task (export from backend code) ```javascript import { Permissions, webMethod } from 'wix-web-module'; import { tasks } from 'wix-crm.v2'; import { elevate } from 'wix-auth'; /* Sample task value: * { * contact: { * _id: '5518ee7f-270e-40c4-b756-dad56e8f0ffc' * }, * description: 'Send a follow up email', * dueDate: new Date(2024, 1, 31), * status: 'ACTION_NEEDED', * title: 'Follow up' * } */ export const myCreateTaskFunction = webMethod(Permissions.Anyone, async (task) => { try { const elevatedCreateTask = elevate(tasks.createTask); const newTask = await elevatedCreateTask(task); console.log('Successfully created a new task:', newTask); return newTask; } catch(error){ console.log(error); // Handle the error } }); /* Promise resolves to: * { * "revision": "1", * "title": "Follow up", * "description": "Send a follow up email", * "dueDate": "2024-01-31T00:00:00.000Z", * "status": "ACTION_NEEDED", * "source": { * "sourceType": "APP", * "appId": "151e476a-715e-ec33-db9a-a7ff4d51f70a" * }, * "contact": { * "firstName": "Sally", * "lastName": "Smith", * "email": "sally.smith@example.com", * "phone": "+1 524-624-2486", * "_id": "5518ee7f-270e-40c4-b756-dad56e8f0ffc" * }, * "_id": "37c2c378-8085-4ef7-8a3e-6f341248e757", * "_createdDate": "2024-01-18T12:16:37.452Z", * "_updatedDate": "2024-01-18T12:16:37.452Z" * } */ ``` ---