Trying to get actor emails of a task for sending emails

1
+1
-1

Using Bonita 6.2.2

I have look all over the forum and have found various answers but none of them work. Possible they are all for version 5.x?

I did fond this post that got closer. It ends up getting a list of users in the form of ActorMember. What I need to their email addresses. I cannot figure out how to get email addresses because of my poor Groovy skill. I see in the API documentation here that ActorMember has four methods. I can get the member ID but I don't know what to do with it.

I also found an old extension that is a jar but I am not sure how to use it.

I also found an old 5.x example process with this script:

import org.ow2.bonita.util.AccessorUtil

def candidates = AccessorUtil.getQueryRuntimeAPI().getTaskCandidates(activityInstance.getUUID())<br />
        def to=""<br />
        for(user in candidates){<br />
            if(to!="") to+=","    <br />
            to+=AccessorUtil.getIdentityAPI().getUser(user).getEmail() <br />
        }<br />
        return to

The issue with this one is that line:

import org.ow2.bonita.util.AccessorUtil

Seems like there are a lot of people in the forums that are looking for the same answer.

Is there someone that can help me get one of these running in 6.2.2?

Comments

Submitted by celine.souchet on Tue, 02/18/2014 - 11:46

Do you want the email of the user assigned to the task, or all users of the actor of the task ?

And, do you want the professional or the personal email ?

3 answers

1
+4
-1
This one is the BEST answer!

Hi,

If you want just the professional email of the user assigned to the task, on your task, you need to add a Groovy connector on Finish, and add the following code :

import org.bonitasoft.engine.identity.ContactData;


ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,taskAssigneeId);
return contactData.email;

If you want to retieve just the candidates to a user task, you need to add a Groovy connector on Enter, and add the following code :

import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.identity.ContactData;

// Get the users attached to the actor member of the human task
final List users = apiAccessor.processAPI.getPossibleUsersOfPendingHumanTask(activityInstanceId, 0, Integer.MAX_VALUE);

// Get the professional email of the users
final List professionalEmails = new ArrayList(users.size());
for(final User user : users){

ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);
professionalEmails.add(contactData.email);

}

return professionalEmails;

Best regards,

Céline

Comments

Submitted by Eric Snyder on Thu, 02/20/2014 - 15:47

I clicked resolved on the wrong answer!!!

The answer by celine.souchet actually resolved this issue.

Submitted by Eric Snyder on Thu, 02/20/2014 - 16:23

Hmmm... I am having an issue. When I tested the script on one task it wen well. Now I have copied the email connector to other tasks. Now I get errors:

Feb 20, 2014 9:18:55 AM org.bonitasoft.engine.log.technical.TechnicalLoggerSLF4JImpl log
WARNING: Error while executing connector with id 23
org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression getPossibleActors with content: import org.bonitasoft.engine.identity.User;

import org.bonitasoft.engine.identity.ContactData;

// Get the users attached to the actor member of the human task

final List users = apiAccessor.processAPI.getPossibleUsersOfPendingHumanTask(activityInstanceId, 0, Integer.MAX_VALUE);

// Get the professional email of the users

final List professionalEmails = new ArrayList(users.size());

final String out = "";

for(final User user : users){

ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);

professionalEmails.add(contactData.email);

out += contactData.email + ",";

}

out = out.substring(0, out.length()-1);

return out; depends on apiAccessor is neither defined in the script nor in dependencies
at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:103)
at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:98)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:150)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:109)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:72)
at org.bonitasoft.engine.core.connector.impl.ConnectorServiceImpl.evaluateInputParameters(ConnectorServiceImpl.java:326)
at org.bonitasoft.engine.connector.ConnectorServiceDecorator.evaluateInputParameters(ConnectorServiceDecorator.java:105)
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:183)
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:147)
at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:207)
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.work(ExecuteConnectorWork.java:119)
at org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork.work(FailureHandlingBonitaWork.java:72)
at org.bonitasoft.engine.work.BonitaWork.run(BonitaWork.java:56)
at org.bonitasoft.engine.work.SequenceRunnableExecutor.innerRun(SequenceRunnableExecutor.java:45)
at org.bonitasoft.engine.work.BonitaRunnable.run(BonitaRunnable.java:35)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: groovy.lang.MissingPropertyException: No such property: apiAccessor for class: Script29
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at Script29.run(Script29.groovy:7)
at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:97)
... 20 more

I checked and resolve dependencies is checked in the script.

Submitted by claudio.taragnolini on Wed, 04/19/2017 - 11:37

this worked for me thanks

1
+1
-1

Source for learning API => what i usually do is look at the source code of Bonita. That's what I did to be able to write a userFilter for multiple user from variable...

Bonita 6.5, I'm using an e-mail connector that gets its e-mail addresses for all possible candidates (not sure the function getPossibleUsersOfPendingHumanTask exists in 6.2)

def emails = [];
def users;

def process_api = apiAccessor.getProcessAPI();
def identity_api = apiAccessor.getIdentityAPI();

def human_task_instance = process_api.getHumanTaskInstance(activityInstanceId);

def start_index = 0;
def max_results = 100;

while( users = process_api.getPossibleUsersOfPendingHumanTask(human_task_instance.getId(), start_index, max_results )) {
        for( user in users ) {
                try {
                        def pro_user = identity_api.getUserWithProfessionalDetails(user.getId());
                        def email = pro_user.getContactData().getEmail();
                        if( email != null ) {
                                emails.add( email );
                        }
                }
                catch( Exception e ) {
                }
        }
        start_index += max_results;
}

emails.unique();
return emails.join( ',' );

1
0
-1

Hi Eric,
The Bonita API has changed in version 6.
Objects used in V5 are not the same that are used in the V6.
For example: The class "AccessorUtil" in the V5 has been replaced by the class "TenantAPIAccessor" in V6.

If you use the groovy script editor embedded in the Bonita Studio, you can use the variable "apiAccessor" provided in the list.

To retrieve the list of candidates to a user task you can use something like this:

ProcessAPI processAPI apiAccessor.getProcessAPI = (); <br />
        List <User> listUsers = processAPI.getPossibleUsersOfPendingHumanTask (ActivityInstanceId, 0, Integer.MAX_VALUE);

To retrieve the user's professional email you can use something like this:
ContactData ContactData = identityAPI.getUserContactData (user.getId (), false);

Hope it can help you
Karim

Comments

Submitted by Eric Snyder on Wed, 02/19/2014 - 19:20

Thank you for the reply. I was out yesterday so this is the first I have been able to look at this. When I use the code above I am getting errors. When I isolate the code to just:

ProcessAPI processAPI apiAccessor.getProcessAPI();
return "Hello";

I get:

ProcessAPI cannot be resolved. It may lead to runtime errors.

processAPI cannot be resolved. It may lead to runtime errors.

What may be wrong?

Also, is there a good source for learning how to use 6.6 API?

Submitted by Eric Snyder on Wed, 02/19/2014 - 23:54

Sorry...6.2 API

Notifications