Can't add email attachment dynamically using Camunda Send-Email Connector


#1

I am using the email-send Connector of Camunda.

I am trying to add attachments dynamically to an auto-generated email. As explained here, the connector requires to specify the values of the variable "fileNames" that references the attachment location at the modeling stage. The value of the variable itself can be changed dynamically at the process execution stage. However, in my case, I would like to dynamically add or retrieve values from the list variable

"fileNames".

The screenshot below shows the static entries that I am using currently to fill the list "fileNames".

My question is : is there a way to specify dynamically (from java code) the values of the

"fileNames" list ? Thanks in advance for your help :slight_smile:


#2

Hi @Hel,

you could use a process variable which includes all file names you want to attach. You can change the variable in your process and reference it in the connector as fileNames.

Does this help you?

Best regards,
Philipp


#3

Hi @Philipp_Ossler,

Thank you for your reply. I appreciate it :blush:

Here is what I tried:

  • Step 1: Create a process variable in a Delegate Class whish is called before the sendEmail Action.
    In this variable, I put all my file names that I want to attach to my email.
    The variable I created has the same name as the connector input parameter fileNames: execution.setVariable("fileNames", fileNamesPath);

  • Step 2: I kept the declaration of “fileNames” input parameter in the process model (as shown in the screenshot below). However, this time, I haven’t specified any item value for the list fileNames. I was hoping, in somehow, the process will pick the values from the process variable names that I created in step 1 but it does not :frowning:

I don’t see how can I reference explicitly the process variable that I created (step 1), in the “fileNames” input parameter of the Connector.
Is there a mean to set the connector input parameter to the process variable I defined earlier ? something like Connector.fileNames=${myfileNamesVariable}?

Looking forward your help.

Best Regards,
Hanane


#4

Hi @Hel,

try to set the input parameter filesNames to type Text and value ${fileNamesPath}. This should use the process variable which is defined in the previous task.

Does this help you?

Best regards,
Philipp


#5

Hi @Philipp_Ossler,

Your tip works like a charm!

I couldn’t imagine that setting the connector parameter fileNames as ‘‘Text’’, which is not complaint to the type that is specified in the connector documentation (List), would never work!

I was expecting a big error caused by an illegal cast of text as a list but fortunately, there was no error :blush:

The engine adapted the type of the text parameter I declared using the type of the referenced process variable: amazingly smart :wink:

Thank you very much for your help!

Best regards,
Hanane


#6

Yeah, in the Camunda Modeler it is not obvious that you can use an expression :sweat_smile: You can find a note in the Camunda docs: https://docs.camunda.org/manual/7.10/reference/bpmn20/custom-extensions/extension-elements/#inputparameter