I created custom task display form and need to add 2 buttons to allow user approve and reject task in display mode. How can I set TaskOutcome value using JS?

My code is the following:

<td class="ms-toolbar" nowrap="nowrap" align="right">
<input id="buttonaccept" type="button" value="Утвердить" onclick="javascript:  somehow set the TaskOutcome value; {ddwrt:GenFireServerEvent('__commit;')}" />


1 Answer 1


If anyone will have the same question - you can do this via client object model supported by Microsoft. Here is a pice of code, which will help you:

  var QueryString = function () {
      // This function is anonymous, is executed immediately and 
      // the return value is assigned to QueryString!
      var query_string = {};
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
         // If first entry with this name
        if (typeof query_string[pair[0]] === "undefined") {
          query_string[pair[0]] = pair[1];
         // If second entry with this name
        } else if (typeof query_string[pair[0]] === "string") {
          var arr = [ query_string[pair[0]], pair[1] ];
          query_string[pair[0]] = arr;
         // If third or later entry with this name
        } else {
        return query_string;
    } ();

    function onQuerySucceeded() {

        //alert('Item updated!');

    function onQueryFailed(sender, args) {

        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

    function updateItem(taskoutcome) {
       var clientContext = new SP.ClientContext.get_current();
       var oList = clientContext.get_web().get_lists().getByTitle('Задачи');
       this.oListItem = oList.getItemById(QueryString.ID);
       oListItem.set_item('TaskOutcome', taskoutcome);
       oListItem.set_item('Status', 'Завершена');

      var bodycontent = document.getElementById('bodytdid').innerHTML;
      oListItem.set_item('Body', bodycontent);

       clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

More details can found in http://vh4u.blogspot.ru/2013/03/sharepoint-2013-approve-and-reject.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.