how to create a task using SPService

345 Views Asked by At

I have used SPService to pull all the task that I have in my task list. I need to know how can I use SPService to create a task in standard SharePoint 2010 Task List.

I was able to create an item using sample code provided in a sample list but need to know what it takes to be able to create an item in Task list.

Thank you

1

There are 1 best solutions below

0
On

The following example demonstrates how to create a Task item using SPServices:

function createTask(taskName,assignedToId, success,error) {
    $().SPServices({
        operation: "UpdateListItems",
        batchCmd: "New",
        listName: "Tasks",
        valuepairs: [["Title", taskName],["AssignedTo", assignedToId]],
        completefunc: function (xData, Status) {
           if (Status == "success") success();
           else error(xData.responseText);
        }
    });
}

Usage

var approverUserId = 10;
createTask('Approve order',approverUserId,
 function(){
   console.log('Task has been created');
 },
 function(error){
   console.log('An error occurred while creating Task');
 });

Key points: