// ---------------Updating task item from javascript Rest API SharePoint // Working code
//--------Check for SP.Data.WorkflowTasksItem //item type
// http://win12sp13:40/_api/web/lists/GetByTitle('Workflow%20Tasks')/ListItemEntityTypeFullName
//--------Check for all properties of list metadata------
//http://win12sp13:40/_api/Web/Lists/GetByTitle('Workflow%20Tasks')/getItemById('5')
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
var item = {
"__metadata": { "type": "SP.Data.WorkflowTasksItem" },
"WorkflowOutcome" : "Completed",
"Status" : "Completed",
"PercentComplete" : 1
};
function appTask()
{
var testUrl = _spPageContextInfo.webAbsoluteUrl+"/_api/Web/Lists/GetByTitle('Workflow%20Tasks')/getItemById(7)";
alert(testUrl);
$.ajax({
url: testUrl,
type: "PATCH",
contentType: "application/json;odata=verbose",
data: JSON.stringify(item),
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"content-Type": "application/json;odata=verbose",
"X-Http-Method": "PATCH",
"If-Match": "*"
},
data: JSON.stringify(item),
success: function (data) {
console.log(data);
alert('success'+ data);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
</script>
<div><input type='button' onclick="Javascript:appTask()" value='Approve'></div>
No comments:
Post a Comment