Case description:
We want to generate printable and send it as attachment by email.
Algorithm of realization:
-
- You should create new business process.
-
Add "Add data" which will create new activity with values:
a. Category - Email (lookup value)
b. Type - Email (lookup value)
c. From
d. To
e. Subject

-
Add "Script task" that will create ActivityFile entity and to generate print form:

Important: Uncheck "For interpreted process" in all blocks "Script task" that describes in this tutorial

Content of following script task:
var reportService = new Terrasoft.Configuration.ReportService.ReportService();
Terrasoft.Configuration.ReportService.ReportData report = reportService.GenerateMSWordReport(
(PrintableId.ToString()), ObjectId.ToString(), ConvertToPdf);
var entity = UserConnection.EntitySchemaManager.GetInstanceByName("ActivityFile");
var fileEntity = entity.CreateEntity(UserConnection);
fileEntity.SetDefColumnValues();
fileEntity.SetColumnValue("ActivityId", AddActivityUserTask.RecordId);
fileEntity.SetColumnValue("TypeId", AttachmentType);
fileEntity.SetColumnValue("Name", "ExamplePrintable.docx");
fileEntity.SetColumnValue("Data", report.Data);
fileEntity.Save();
return true;
PrintableId - Id of your printable from "Printable" lookup
ObjectId - Id of object for which we will generate printable
ConvertToPdf (bool) - if false than will generate printable with type .docx else .pdf
AddActivityUserTask.RecordId - Id of "Add activity" block that we added above
AttachmentType - value "File" from lookup "Attachment Type"

"ExamplePrintable.docx" - name of generated file
Important: you should add type of file (.docx or .pdf). It depends on bool argument when you generate printable by using "GenerateMSWordReport"
report.Data - generated printable
-
Add "Script task" that will send email with created attachment:

Uncheck "For interpreted process"
Add next usings for process: Terrasoft.Mail, Terrasoft.Mail.Sender, Terrasoft.Core.Factories:

- Add following content:
var activityId = AddActivityUserTask.RecordId;
var emailClientFactory = ClassFactory.Get<EmailClientFactory>(new ConstructorArgument("userConnection", UserConnection));
var activityEmailSender = new ActivityEmailSender(emailClientFactory, UserConnection);
activityEmailSender.Send(activityId);
return true;
AddActivityUserTask.RecordId - Id of added email activity from "Add email activity" block
Example:
I need to generate printable and send it as attachment by email when status of contract was changed on signed
- I created business process and add next parameters

MailSender - value from lookup "Mailbox synchronization settings". (Values in this lookup becomes allow when you sign in in BPMonline by your mail account)
Printable Id - Id of printable from lookup "Printable" which i want to use
2. Added signal "Contact signed" which start business process when Status becomes "Signed"

3. Added "Formula" block "Set signed contract id" that sets "Signed contract id" parameter on Id of contact that was signed

4. Added "Read data" that gives parameter "MailSender" and returns string value "Sender's email" (it uses for sending email)

5. Added "Read data" that gives parameter "Printable Id" and returns columns: Convert to PDF (bool) and Title of printable

6. Added "Formula" block "Set ConvertToPdf" that sets "Convert To Pdf" parameter on bool value from "Read Printable"

7. Added "Formula" block "Set File Name" that sets "File name" parameter on Text value which is formed by "Title" and "Convert to pdf" value (bool) for current record from lookup "Printable"

Formula value:
[#Read Printable.First item of resulting collection.Title#] + ([#Convert To Pdf#] ?
".pdf"
:
".docx"
)
8. Added "Add data" block "AddActivityUserTask" that create email activity by using added parameters

9. Added "Generate print form" script task with following content:
var reportService = new Terrasoft.Configuration.ReportService.ReportService(UserConnection);
Terrasoft.Configuration.ReportService.ReportData report = reportService.GenerateMSWordReport(
(PrintableId.ToString()), SignedContractId.ToString(), ConvertToPdf);
var entity = UserConnection.EntitySchemaManager.GetInstanceByName("ActivityFile");
var fileEntity = entity.CreateEntity(UserConnection);
fileEntity.SetDefColumnValues();
fileEntity.SetColumnValue("ActivityId", AddActivityUserTask.RecordId);
fileEntity.SetColumnValue("TypeId", AttachmentTypeId);
fileEntity.SetColumnValue("Name", FileName.ToString());
fileEntity.SetColumnValue("Data", report.Data);
fileEntity.Save();
return true;
10. Added "Send email" script task with following content:
var activityId = AddActivityUserTask.RecordId;
var emailClientFactory = ClassFactory.Get<EmailClientFactory>(new ConstructorArgument("userConnection", UserConnection));
var activityEmailSender = new ActivityEmailSender(emailClientFactory, UserConnection);
activityEmailSender.Send(activityId);
return true;
The final business process:

MD file of business process for import (Version 7.10.2) is attached.