Totvs Fluig - Customization - Call in REST service in beforeSendData event

Asked

Viewed 1,801 times

3

Does anyone know how to make a call to a REST service within the beforeSendData event, follow below my code (not functional):

My goal is to run a call on a REST service of the fluig itself in order to get the detail of a request (process instance).

I tried using the standard jQuery call but it didn’t work, this script runs on the 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********");
        }
    });     
}

  • Yes, in the log the message appears stating that WCMAPI is not defined. Referenceerror: "WCMAPI" is not defined.

  • Process event, I intend to get information of the process task to know if it is expired to feed the Analytics.

  • @Eduardoseixas does not work, the problem is that the global variable WCMAPI is not available in scopo, when I do what you suggested appears the following message in the log. 13:42:36,743 ERROR [com.datasul.technology.webdesk.customization.Customizationmanager] (http-pool-threads - 8) ERROR WHEN RUNNING SCRIPT -> NOK - sun.org.Mozilla.javascript.Internal.Ecmaerror: Referenceerror: "WCMAPI" is not defined. (<Unknown source>#48) in <Unknown source> at line number 48

  • In this article [http://tdn.totvs.com/display/public/fluig/Desenvolvimento+de+Eventos#Developmentevents-Workflowtasksvo] I could use this VO to obtain the data, but it is not available in the scope either.

  • I need to get data from the process, in this case I need to know if the activity being performed is within the SLA or if it is delayed. There are several methods available in the global variable Hapi but none that is document brings this information.

  • The fillStatusTask method requires login and password from the user who wants to get the delayed tasks. Anyway, this data is for Analytics, I have to pick up the task event to send in the smallest granularity possible. Item by item. If the Workflowtasksvo object was available at process events it would solve my problem, or if the javascript server api allows me to call a webservice I would call the url /ecm/api/Rest/ecm/workflowView/findDetailsMyRequests passing the process id and the user id.

  • It would be a breach of security if the system let me get the password of the currently logged in user. You probably use a default user/password for system operations.

  • I can’t get the password even if it’s encrypted by the user, and even if I could get it encrypted it wouldn’t be worth it because the system would re-encrypt to validate the user and the login would fail. Apparently there is no way to call an address (url) through the Javascript server side of Fluig.

  • I will try to implement a Java webservice and call it through javascript, so I will make Ws request the URL, get the information and pass it on to js. .

  • I found that they use the Fluig Javascript Rhino engine, so I can run the following code using the Java API and apache: code&#xA;var url = "http://google.com";&#xA;var get = new org.apache.commons.httpclient.methods.GetMethod(url);&#xA;var client = new org.apache.commons.httpclient.HttpClient();&#xA;var br = new java.io.BufferedReader(new java.io.InputStreamReader(get.getResponseBodyAsStream())); var Response = ""; var line = br.readline(); while(line != null){ Response = Response + line; line = br.readline(); } log.info(Response); get.releaseConnection(); code

  • Sorry for the delay, yes, I solved.

  • I solved it as specified above using the Java API as described in the comment on 12/02/15. I appreciate the dedication.

Show 7 more comments

1 answer

1


I’ve turned your comment into an answer, so the question doesn’t go unanswered, and it can help other people. Take it as correct, if applicable. I made the corrections in the variable declarations, you do not need to put var at all, just at the beginning, separating with comma.

var url = "google.com",
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();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.