javascript – Totvs Fluig – Customization – Call in REST service in beforeSendData event

Question:

Does anyone know how I can make a call to a REST service inside the beforeSendData event, here is my code (non-functional):

My objective is to execute a call in a Fluig's own REST service in order to get the details of a request (process instance).

I tried using the standard jQuery call but it didn't work, this script runs server-side.

 function beforeSendData(customFields, customFacts) { log.info("****************teste"); customFields[0] = "1"; customFacts[0] = 10.53; var processInstanceId = getValue("WKNumProces"); var taskUserId = getValue("WKUser"); log.info("****************teste"); //Tentei usar esta API mas não funciona //Tentei usar jQuery mas também não funcionou. WCMAPI.Read({ type: "POST", url: WCMAPI.getServerURL() + '/ecm/api/rest/ecm/workflowView/findDetailsMyRequests?processInstanceId=' + processInstanceId + "&taskUserId=" + taskUserId, async: false, success: function funcao(data) { log.info(txt); var data = jQuery.parseJSON(txt); }, error: function (msg){ log.info("****Não funcionou********"); } }); }

Answer:

I've turned your comment into an answer, so the question doesn't go unanswered, and it can help others. Accepted as correct, if applicable. I made the corrections in the variable declarations, you don't need to put var in all, just at the beginning, separating with a comma.

var url = "google.com.br",
get = new org.apache.commons.httpclient.methods.GetMethod(url),
client = new org.apache.commons.httpclient.HttpClient(),
br = new java.io.BufferedReader(newjava.io.InputStreamReader(get.getResponseBodyAsStream())),
response = "",
line = br.readLine();
 while(line != null)
 {
   response = response + line; 
   line = br.readLine()
 } 

log.info(response); 
get.releaseConnection();
Scroll to Top