Advertisement
EvaldoMaciel

Cancelado processos via API

Feb 23rd, 2021
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cancelar(id, usuario) {
  2.     var settings = {
  3.         "url": "/api/public/2.0/workflows/cancelInstance",
  4.         "method": "POST",
  5.         "timeout": 0,
  6.         "async": false,
  7.         "headers": {
  8.             "Content-Type": "application/json"
  9.         },
  10.         "data": JSON.stringify({ "processInstanceId": id, "cancelText": "Cancelado por API", "replacedId": usuario }),
  11.     };
  12.     $.ajax(settings).done(function (response) {
  13.         console.log(response.content);
  14.         return response.content;
  15.     });
  16. }
  17.  
  18. function consultar(usuario) {
  19.     var settings = {
  20.         "url": "/ecm/api/rest/ecm/centralTasks/getTasks/requests/" + usuario + "?rows=50&page=1",
  21.         //"url": "/ecm/api/rest/ecm/centralTasks/getTasks/manager/" + usuario + "?rows=100&page=1",
  22.         "method": "GET",
  23.         "async": false,
  24.         "timeout": 0,
  25.         "headers": {
  26.             "Content-Type": "application/json"
  27.         },
  28.     };
  29.     var retorno = $.ajax(settings).done(function (response) {
  30.         return response;
  31.     });
  32.     return retorno;
  33. }
  34.  
  35. function repeticao(usuario) {
  36.     var retornoCons = consultar(usuario);
  37.     for (var index = 0; index < retornoCons.responseJSON.invdata.length; index++) {
  38.         var element = retornoCons.responseJSON.invdata[index];
  39.         console.log(element.processInstanceId);
  40.         cancelar(element.processInstanceId, usuario);
  41.         console.log(index == parseInt(retornoCons.responseJSON.invdata.length - 1))
  42.         if (index == parseInt(retornoCons.responseJSON.invdata.length - 1)) {
  43.             console.clear();
  44.             console.log("Acabou");
  45.             setTimeout(() => {
  46.                 start(usuario)
  47.             }, 500);
  48.             return "Acabou";
  49.         }
  50.     }
  51. }
  52.  
  53. function start(params) {
  54.     return repeticao(params);
  55. }
  56.  
  57. start("academy.aluno");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement