Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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;')}" />
</td>

Thanks

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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 {
          query_string[pair[0]].push(pair[1]);
        }
      } 
        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);

       oListItem.update();              
       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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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