<div id='codeeditor1-template'>
<script>
function updateListItem(siteUrl, listTitle, listItemId, itemUpdateProperties) {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(listTitle);
this.oListItem = oList.getItemById(listItemId);
for(var i=0;i<itemUpdateProperties.length;i++){
oListItem.set_item(itemUpdateProperties[i].FieldName, itemUpdateProperties[i].Value);
}
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, function(){}), Function.createDelegate(this, function(){}));
}
function approveTask(){
var taskId = 1;
var dataFields = new Array();
dataFields[dataFields.length] = {FieldName:"TaskOutcome", Value:"Approved"}
dataFields[dataFields.length] = {FieldName:"Status", Value:"Completed"}
dataFields[dataFields.length] = {FieldName:"PercentComplete", Value:1}
dataFields[dataFields.length] = {FieldName:"Body", Value:"All looking good"};
updateListItem("/sites/testsite", "Workflow Tasks", taskId, dataFields);
}
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
approveTask();
});
</script>
</div>
<div id='codeeditor2-template'>
<script>
function updateListItem(siteUrl, listTitle, listItemId, itemUpdateProperties) {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle(listTitle);
this.oListItem = oList.getItemById(listItemId);
for(var i=0;i<itemUpdateProperties.length;i++){
oListItem.set_item(itemUpdateProperties[i].FieldName, itemUpdateProperties[i].Value);
}
oListItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, function(){}), Function.createDelegate(this, function(){}));
}
function rejectTask(){
var taskId = 1;
var dataFields = new Array();
dataFields[dataFields.length] = {FieldName:"TaskOutcome", Value:"Rejected"}
dataFields[dataFields.length] = {FieldName:"Status", Value:"Completed"}
dataFields[dataFields.length] = {FieldName:"PercentComplete", Value:1}
dataFields[dataFields.length] = {FieldName:"Body", Value:"All looking good"};
updateListItem("/sites/testsite", "Workflow Tasks", taskId, dataFields);
}
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
rejectTask();
});
</script>
</div>
Tasks can be approved with the following javascript code;
CODE
Tasks can be rejected with the following javascript code;
CODE