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.SetDefColumnValues();
fileEntity.SetColumnValue("ContactId", ContactId);
fileEntity.SetColumnValue("TypeId", AttachmentType);
fileEntity.SetColumnValue("Name","MyPrintable.docx");
fileEntity.SetColumnValue("Data", report.Data);
fileEntity.Save();

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

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. 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 *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!