i m using community version ,
i make leave approval process with 3 stage of approval level .
i want to send email after case completed with complete case history
i know i should coding and create connector for it .
but i want to know by which bonita api i can get this detail and how . ?
i short , i want to access all comment is generated at dashboard of user portal , how to get this comment and store into variable to email it
Hi,
In first, you need a Groovy connector on the last task of your process, on finish.
In this connector, put the following code :
// Get the 100 first archived cases
import org.bonitasoft.engine.bpm.process.ArchivedProcessInstance;
import org.bonitasoft.engine.bpm.process.ArchivedProcessInstancesSearchDescriptor;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.Order;
import org.bonitasoft.engine.api.ProcessAPI;
ProcessAPI processAPI = apiAccessor.getProcessAPI();
SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 100);
searchOptionsBuilder.filter(ArchivedProcessInstancesSearchDescriptor.PROCESS_DEFINITION_ID, processDefinitionId);
searchOptionsBuilder.sort(ArchivedProcessInstancesSearchDescriptor.ARCHIVE_DATE, Order.ASC);
List archivedProcessInstances = processAPI.searchArchivedProcessInstances(searchOptionsBuilder.done()).getResult();
return archivedProcessInstances ;
If you want get all comments of a case, use the following code, with processInstanceId as the identifier of the case where you have comments :
import org.bonitasoft.engine.bpm.comment.ArchivedComment;
import org.bonitasoft.engine.bpm.comment.ArchivedCommentsSearchDescriptor;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.Order;
import org.bonitasoft.engine.api.ProcessAPI;
ProcessAPI processAPI = apiAccessor.getProcessAPI();
SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 100);
searchOptionsBuilder.filter(ArchivedCommentsSearchDescriptor.PROCESS_INSTANCE_ID, processInstanceId);
searchOptionsBuilder.sort(ArchivedCommentsSearchDescriptor.ARCHIVE_DATE, Order.ASC);
List archivedComments = processAPI.searchArchivedComments(searchOptionsBuilder.done()).getResult();
return archivedComments ;
Best regards,
Céline
Thank you so much ,
but i m new in this environment . can u pl elaborate in detail how to do it ,
after create connector and paste code , by which variable i can save output of it ?
pl describe in detail if possible .
i really need it
thanks
Hi,
you need to create a data on your process (if you want use it on several tasks) or your task.
On your Groovy connector, save the output on your new data.
If you want to send an email, create a task, and add an Email connector (no need Groovy connector, and datas).
Set all fields and steps. For the field “Message”, click on “Change editor”, and the pencil next.
A pop-up will open. Select “Script” (is an Groovy script). Put the code on (without the return), and build the message that you want to send, and return it.
Best regards,
Céline
Thank you so much for reply ,
But i can’t figure out exactly what i should do because .
-
on last task i create email connector and in message body i just paste 2nd code which you provide , but it return java.list . no how to put in message . i wirte code without return it failed on execution
-
i create one data variable on last task data with variable type : java.util.list and available value : your code .
but still get failed state at execution
what should i do, what i mismatch .
how to figure out
Do you select “Script” in the pop-up for the message ?
What you want display in your message ? Just the comment of your case ?
For this, in the message, use this :
import org.bonitasoft.engine.bpm.comment.ArchivedComment;
import org.bonitasoft.engine.bpm.comment.ArchivedCommentsSearchDescriptor;
import org.bonitasoft.engine.search.SearchOptionsBuilder;
import org.bonitasoft.engine.search.Order;
import org.bonitasoft.engine.api.ProcessAPI;
ProcessAPI processAPI = apiAccessor.getProcessAPI();
SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0, 100);
searchOptionsBuilder.filter(ArchivedCommentsSearchDescriptor.PROCESS_INSTANCE_ID, processInstanceId);
searchOptionsBuilder.sort(ArchivedCommentsSearchDescriptor.POSTDATE, Order.ASC);
List archivedComments = processAPI.searchArchivedComments(searchOptionsBuilder.done()).getResult();
StringBuilder builder = new StringBuilder();
for(final ArchivedComment archivedComment : archivedComments){
builder.append(archivedComment.getPostDate() + " : " + archivedComment.getContent());
}
return builder.toString();
My bad, you can’t sort the archived comment on ARCHIVE_DATE.