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.