Running a Word Printable in a Process Script Task and Add as Attachment on a Record in Creatio (formerly bpm’online)

Script Tasks in bpm’online processes allows you to go beyond what is available in the standard process tasks. There’s really nothing you can’t accomplish, as long as you know what code to write. The following code will run a Word printable and attach the resulting document to a record.

In the code below, we will get a reference to the ReportService, run the printable (passing in the ID of the printable, the ID of the entity we’re running it for, and a boolean indicating if we want the result as a PDF or not (otherwise Word doc). Then, we’ll create a new ContactFile entity to store the document data. Note, in this sample, I am attaching to a contact and creating a ContactFile record. You could modify this to use ActivityFile, AccountFile, etc, as needed.

var reportService = new Terrasoft.Configuration.ReportService.ReportService();

// run printable
Terrasoft.Configuration.ReportService.ReportData report = reportService.GenerateMSWordReport(PrintableId.ToString()), ContactId.ToString(), ConvertToPdf);

// add as attachment to contact
var entity = UserConnection.EntitySchemaManager.GetInstanceByName("ContactFile");
var fileEntity = entity.CreateEntity(UserConnection);
fileEntity.SetColumnValue("ContactId", ContactId);
fileEntity.SetColumnValue("TypeId", AttachmentType);
fileEntity.SetColumnValue("Data", report.Data);

After that runs you’ll see the file attached to the contact.

Want content like this delivered to your inbox? Sign up for our newsletter!

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

Submit a Comment

Your email address will not be published. Required fields are marked *