Send Email to task assignee with task name & link

My ask is simple, I want to send email to task owner as soon as a task is assigned to him or her. The email subject should contain name of the task and if possible link to it. What I have was able to achieve so far is below

Create email connector which executes on start of task
To get dynamic task name I tried using below code

apiAccessor.getProcessAPI().getActivityInstance(activityInstanceId).displayName)

but this always returns null. Any thoughts ?

You should try the following code instead:

apiAccessor.getProcessAPI().getActivityInstance(activityInstanceId).getDisplayName()

At the moment when connector is executed on enter, dynamic name is still not available, that is why it returns null value. You can use getName() method, that will get the name of the task, or you can use the same expression as you put in the Display name of the task (script, variable etc.). That way you would be able to produce the same name as it will be done for the display name once the task becomes available.

Hi,

I used the following:

String body = "Estimado usuario:

" body += "Le ha sido asignada una nueva tarea, de clic "; body += "aquí" body += " para más información.

"; body += "Cordialmente.
" body += "El equipo de Procesos.";

return body;

and it worked for us.

IMPORTANT you need to use a "" (slash) before $ in the line “entry&mode” because in other way Groovy try to use an object called “entry”.

Lucky!

Try
apiAccessor.getProcessAPI().getActivityInstance(activityInstanceId).getName()

I had already given that a try the result is same. The same code works in a plain old groovy script, but not within email connector.

Show. Realy work.

Yes this works Thanks! Now coming to other part of my question how do I get link to task in email body ?

You will find how to get a task url in our online documentation here .

Thank you for provideing link .
but i can’t figured out at where i have to write that code .

i m writeing that code on email body : script editior

gives following warning :
buffer cannot be resolved. It may lead to run time errors.

StringBuffer buffer = new StringBuffer(“URL: <a href="”);
buffer.append(“http://”);
buffer.append(host);
buffer.append(“:”);
buffer.append(port);
buffer.append(“/bonita?ui=form&locale=en#form=”);
buffer.append(processName); buffer.append(“–”);
buffer.append(processVersion); buffer.append(“–”);
buffer.append(activityName); buffer.append(“$entry&mode=app&task=”);
buffer.append(activityInstanceId);
buffer.append(“">here”);
return buffer.toString();

at at execution it fails

Try to switch editor from Wysiwyg (rich text) to expression editor and create a script that will generate this html code.

thank you for reply
but i can’t elobare how to do it .

i create email connector and in message (body)
click on switch to editer .
then i click on pencil icon for go to ediotor
then
expresion type : script
interpreter : groovey
and paste code

StringBuffer buffer = new StringBuffer("URL: here"); return buffer.toString();

when try to execute eamil connector give following 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

pl help

hey, have you found a solution to this???

Hi,me too i want to know the solution.

regards
Yassine