0

I have the List1 which creates a Task when an item is inserted. I have to approve this task via Javascript. I found some examples, one of these:

var clientContext = new SP.ClientContext("MySiteUrl");
var oList = clientContext.get_web().get_lists().getByTitle('MyTasks');

var oListItem = oList.getItemById(1);
oListItem.set_item('WorkflowOutcome', 'Approved');
oListItem.set_item('FormData', 'Approved');
oListItem.set_item('Status', 'Genehmigt');
oListItem.set_item('PercentComplete', 1);
oListItem.set_item('Completed', true);
oListItem.update();

clientContext.executeQueryAsync(..);

All the fields but WorkflowOutcome are update and the workflow does not continue. What can I do in order to change the state of WorkflowOutcome and make the wolkflow continue?

  • Some voice in the back of my head says WorkflowOutCome wants a number, not (localized) Strings. And I think Completed is a Formula which uses [% Complete], so setting it to true doesn't do anything – Danny '365CSI' Engelman Jan 14 '16 at 14:35
  • Well, if i look to the definition of Completed , it says Yes/No-Field.... And about WorkflowOutCome , looking on the examples on the web, all people set a string.. – Emaborsa Jan 14 '16 at 14:52
  • Those voices in the back of my head.... a good thing I run on Lithium – Danny '365CSI' Engelman Jan 14 '16 at 15:49
  • And those voices keep talking... you have a German word for Status, does WorkflowOutcome need to be localized?? – Danny '365CSI' Engelman Jan 14 '16 at 15:57
  • My SP is in German and also its values. – Emaborsa Jan 14 '16 at 21:53
1

I've been stuck on the same problem as Emaborsa. It's not well documented but Status and FormData (and Completed) are important fields. Status field in particular has to be set to "Approved" even though the field's valid choices for my install shows as

<Field Type="Choice" ID="{c15b34c3-ce7d-490a-b133-3f4de8801b76}" Name="Status" DisplayName="Status" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Status" ColName="nvarchar4" Indexed="TRUE" Version="1" RowOrdinal="0"><CHOICES><CHOICE>Not Started</CHOICE><CHOICE>In Progress</CHOICE><CHOICE>Completed</CHOICE><CHOICE>Deferred</CHOICE><CHOICE>Waiting on someone else</CHOICE></CHOICES><MAPPINGS><MAPPING Value="1">Not Started</MAPPING><MAPPING Value="2">In Progress</MAPPING><MAPPING Value="3">Completed</MAPPING><MAPPING Value="4">Deferred</MAPPING><MAPPING Value="5">Waiting on someone else</MAPPING></MAPPINGS><Default>Not Started</Default></Field>

this can been seen via rest api. /_api/Web/Lists/GetByTitle('tasks')/Fields

A really old post mentions similar problem in 2010. JavaScript OM to Approve Designer Workflow Task

You might want to try setting Status to "Approved" instead of 'Genehmigt' even though you are using German. Also, You should try approving a simple approval workflow that is close to out-of-the-box.

Hope this helps.

  • Thanks! I figured out that WorkflowOutcome has to be in english, Status can also be in another language. – Emaborsa Jan 22 '16 at 9:24
0

This code works in updating task correctly.

   var ctx = SP.ClientContext.get_current();
   var list = ctx.get_web().get_lists().getByTitle("Workflow Tasks");
    var item = list.getItemById(2);
    item.set_item('Completed',true);
    item.set_item('PercentComplete',1);
    item.set_item('FormData','Completed');
    item.set_item('Status','Approved');
    item.set_item('WorkflowOutcome','Approved');
    item.update();
    ctx.executeQueryAsync(
      function() {
         alert('Updated successfully');
      },
      function(sender,args){
         alert('Error occured '+ args.get_message());
      }
    );
  • Doesn't work, i mean...all fields but WorkflowOutcome are set and the workflow does not continue. – Emaborsa Jan 14 '16 at 14:55
  • indeed strange..I have used this code and it worked..you need to check what is causing the issue.there could be definitely something else going on. – user13408 Jan 14 '16 at 14:58
  • No sorry, acctually alle the fields get updated, there must have been something wrong. However, the workflow does not continue. – Emaborsa Jan 14 '16 at 15:13
  • 'Completed' is a Boolean (fieldtype 17) with Formula =[% Complete]=1 in my default Office365 TaskList; it is a Microsoft special, because it displays the checkbox in a View. – Danny '365CSI' Engelman Jan 14 '16 at 15:54
  • OK.... might you also be able to solve my problem? – Emaborsa Jan 14 '16 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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