send an email to a user for next task

Hi i’ve been trying to send an email for a user to the next task
what i did was this create a list variable and then created a script

import org.bonitasoft.engine.identity.User; import org.bonitasoft.engine.identity.ContactData; import org.bonitasoft.engine.bpm.actor.ActorCriterion;

// 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 operations_manager = new ArrayList(users.size());
for(final User user : users){

ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);
if (contactData!=null && contactData.getEmail()!=null && !contactData.getEmail().isEmpty()) {

operations_manager.add(contactData.email);}

}

return operations_manager

but i keep getting this error

java.lang.reflect.InvocationTargetException
org.bonitasoft.engine.bpm.connector.ConnectorExecutionException: org.bonitasoft.engine.core.connector.exception.SConnectorException: org.bonitasoft.engine.expression.exception.SInvalidExpressionException: Declared return type class java.lang.Long is not compatible with evaluated type class java.lang.Integer for expression activityInstanceId

can someone please help? i’m using latest version bonitasoft 6.3.2

Hi,

the error seems not related to the specified script.

Please check the Return type of your scripts and validate that the return types are correct.

It might occur when you are trying to initialize the activityInstanceId variable which is not of correct type.

Regards,

Hi, you can get emails following way

getCurrentUserEmail

def email = BonitaUsers.getUserProfessionalContactInfo(apiAccessor, taskAssigneeId).email
return email`

getSpecificGroupEmails

import org.bonitasoft.engine.identity.ContactData
import org.bonitasoft.engine.identity.Group
import org.bonitasoft.engine.identity.User
import org.bonitasoft.engine.identity.UserCriterion

Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath("/GROUP_PATH_IN_YOUR_ORGANIZATION")
List<User> usersInGroup=apiAccessor.getIdentityAPI().getUsersInGroup(groupSelected.getId(), 0, 100, UserCriterion.FIRST_NAME_ASC)
StringBuilder sb=new StringBuilder()
for (User user:usersInGroup){
	   //get professional contact data
	   ContactData contactData = apiAccessor.getIdentityAPI().getUserContactData(user.getId(), false)
		if (contactData!=null && contactData.getEmail()!=null && !contactData.getEmail().isEmpty()){
		   sb.append(contactData.getEmail()).append(",")
	 }
}
return sb.toString()

Hope it helps :slight_smile:

Hi thank you for your response
but return type it’s disabled and i cannot change it and everytime i try to use activityinstanceId
i get the same error
i recorded a video with it’s current behavior http://screencast-o-matic.com/watch/c2QeqInP5G
can you please help :frowning: i’ve been stuck with this for a while now

Hi,

did you defined you rown variable activityInstanceId or are you using the provided one by Bonita?

Regards,

im using the one provided by bonita