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.
– José Fabio Coimbra
Process event, I intend to get information of the process task to know if it is expired to feed the Analytics.
– José Fabio Coimbra
@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
– José Fabio Coimbra
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.
– José Fabio Coimbra
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.
– José Fabio Coimbra
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.
– José Fabio Coimbra
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.
– José Fabio Coimbra
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.
– José Fabio Coimbra
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. .
– José Fabio Coimbra
I found that they use the Fluig Javascript Rhino engine, so I can run the following code using the Java API and apache:
code

var url = "http://google.com";
var get = new org.apache.commons.httpclient.methods.GetMethod(url);
var client = new org.apache.commons.httpclient.HttpClient();
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
– José Fabio Coimbra
Sorry for the delay, yes, I solved.
– José Fabio Coimbra
I solved it as specified above using the Java API as described in the comment on 12/02/15. I appreciate the dedication.
– José Fabio Coimbra