Create subtask in task list via client javascript in sharrepoint 2013

1307 ワード

Note:We coucld create new subtask in task list directly,but sometimes we need new subtask from parent and create it by coding aut.the impoint is shatwe Shot know the ite「Parthere ID」  the ID of parent task、そして、 when we create a new item in the task list、just set the PantID of the new item、finally the ite will inheit the parent task aut.
Now,I will create a subtask from the parent task with the PantID.
Here is the code:
function newSubTask(){
	var clientContext = new SP.ClientContext.get_current();
	var oList = clientContext.get_web().get_lists().getByTitle('Task Management');
	var itemCreationInfo = new SP.ListItemCreationInformation();
	this.oListItem = oList.addItem(itemCreationInfo);
	oListItem.set_item('Title', 'new001');
	oListItem.set_item('ParentID', '1');
	oListItem.update();
	clientContext.load(oListItem);
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this        .onQueryFailed));
}

function onQuerySucceeded() {
    alert('Item created: ' + oListItem.get_id());
}

function onQueryFailed(sender, args) {
   alert('Request failed. ' + args.get_message() + '
' + args.get_stackTrace()); }