Getting Bonita Portal Comments into task forms

1
0
-1

Hello all,

I'm trying to get Portal comments into a form task. For a first try, I want every comments without any other filter than being the current Case. I don't know what's wrong. I'll appreciate any help you may provide. Thanks.

I coded a groovy expression in a text area widget (General > Data > Initial value):

import org.bonitasoft.engine.api.ProcessAPI;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.engine.search.impl.SearchResultImpl;
import org.bonitasoft.engine.search.impl.SearchOptionsImpl;
import org.bonitasoft.engine.search.impl.SearchFilter;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.bpm.comment.Comment;

ProcessAPI proAPI = apiAccessor.getProcessAPI();
SearchOptionsBuilder filtro = SearchOptionsBuilder.filter('processInstanceId', processInstanceId);
List<Comment> comentarios = proAPI.searchComments(filtro.getFilters());
return comentarios.toArray().toString();

This is what I get at engine log: 2014-09-15 16:02:30 org.bonitasoft.forms.server.FormsServletExt SEVERE: Error while getting the first page for id Expense Claim--1.3--1st Approval$entry org.bonitasoft.forms.server.exception.FormInitializationException: Error when evaluating expressions on activity instance 60107. Error on expression evaluation for the attribute [initial-value] of object [additionalNotes1]. at org.bonitasoft.forms.server.provider.impl.FormServiceProviderImpl.resolveExpressions(FormServiceProviderImpl.java:910) at org.bonitasoft.forms.server.FormsServletExt.resolveFormFieldExpressions(FormsServletExt.java:401) at org.bonitasoft.forms.server.FormsServletExt.setFormFieldValues(FormsServletExt.java:354) at org.bonitasoft.forms.server.FormsServletExt.setFormFieldValues(FormsServletExt.java:323) at org.bonitasoft.forms.server.FormsServletExt.getFormFirstPage(FormsServletExt.java:167) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561) at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208) at org.bonitasoft.forms.server.FormsServlet.processCall(FormsServlet.java:138) at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248) at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62) at javax.servlet.http.HttpServlet.service(HttpServlet.java:643) at javax.servlet.http.HttpServlet.service(HttpServlet.java:723) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.bonitasoft.console.common.server.sso.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.bonitasoft.console.common.server.login.filter.NoCacheFilter.doFilter(NoCacheFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.bonitasoft.console.security.SessionFixationValve.invoke(SessionFixationValve.java:77) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)

1 answer

1
0
-1
This one is the BEST answer!

Ola / Hi Ana

Try with this code, note that I instantiated SearchOptionsBuilder, I set up this on done status, and I get the result from the SearchResult which is a List :)

import org.bonitasoft.engine.api.ProcessAPI;
import org.bonitasoft.engine.session.APISession;
import org.bonitasoft.engine.search.impl.SearchResultImpl;
import org.bonitasoft.engine.search.impl.SearchOptionsImpl;
import org.bonitasoft.engine.search.impl.SearchFilter;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.bpm.comment.Comment;
import org.bonitasoft.engine.bpm.comment.SearchCommentsDescriptor;
 
ProcessAPI proAPI = apiAccessor.getProcessAPI();
SearchOptionsBuilder filtro = new SearchOptionsBuilder(0,Integer.MAX_VALUE);
filtro.filter(SearchCommentsDescriptor.PROCESS_INSTANCE_ID, processInstanceId);

List<Comment> comentarios = proAPI.searchComments(filtro.done()).getResult();
return comentarios.toArray().toString();

And as a comment, it is better to use the SearchDescriptor instead of a constant, it can change in further versions...

You can find more examples on searches here http://documentation.bonitasoft.com/search/site/SearchOptionsBuilder

Cheers

Comments

Submitted by ana.santiago on Tue, 09/16/2014 - 12:58

Hi, Thank you very much. That's what I was searching for. I've seen information about the SearchCommentsDescriptor and suppose that KIND may be used to identify user comments (in order to ignore system comments), but I don't know exactly what values I may use in the descriptor. Didn't find that in documentation. Cheers

Submitted by Pablo Alonso de... on Tue, 09/16/2014 - 14:16

Ana, if you use the method searchCommentsInvolvingUser you will see the ones related with user [no system ones], may be is useful for you

                SearchResult<Comment> commentResult = pAPI.searchCommentsInvolvingUser(user.getId(),soU);
                for(Comment c : commentResult.getResult()){                    
                        System.out.println(c);
                }

And as note, in subscription you can disable it and/or translate them (system ones)

Submitted by ana.santiago on Tue, 09/16/2014 - 16:41

Thanks Pablo, That's not exactly what I was searching for. I wanted to exclude system messages and display only user messages in a task form: it may be any user that participate in the instance. I've managed to get this to work: because system messages don't have a userId, when displaying messages, I ignored them. Thanks for all your support. :)

Submitted by Pablo Alonso de... on Wed, 09/17/2014 - 11:11

you´re welcome :)

Have Fun with Bonita

Notifications