+44(0)1908 545 770
YOUR EXPERT RPA PARTNER

Team up with our RPA strategy and tech specialists for maximum automation impact

Find out more
Harness the power of UiPath in your business.
WATCH NOW

Save money and spend more time on priority work.

Book consultation
READY, SET, AUTOMATE

Let's choose, design and deploy a process automation solution for your business.

Find out more
TRANSFORM YOUR BUSINESS

Let's analyse your business to discover opportunities for innovation and automation.

Find out more

Begin your business transformation journey

Book consultation
AUTOMATE EVERY FUNCTION

Automate where it matters most. Scale to solve challenges in every area

Find out more
GIVE EVERY TEAM THE TOOLS FOR SUCCESS

Equip people with user-friendly solutions that save time and make work easier

Find out more

Which business problem
can we solve first?

Book consultation
14 October 2015

How to generate a Word document from a K2 SmartForm

Generating documents from workflow systems is common.  In fact, record generation in the form of a digital document is a common output of a K2 workflow.  For example, if a service plan is approved in a workflow, a version of the plan is generated using data stored in a database and pushed into SharePoint for storage.

K2 Automated Testing Software

BenchQA allows full test automation of K2, including fully automated K2 SmartForms and K2 Workflow testing. It promotes test driven development for K2 and ensures continued quality assurance for K2 solutions. Easily apply changes to test cases to accommodate changes to K2 apps and ensure all apps are regression tested to avoid defects and assure continuous quality.

 

Free K2 Five Upgrade Review

Data in K2 is exposed using K2 SmartObjects.  These are unbelievable flexible objects that allow data access to virtually any data source.  This means we can inject data from lost of different locations in something like a Word document.  This blog step through this process and explains how to generate Word documents using K2 blackpearl and SmartObjects.  In this instance I will show how to generate a document that lists all the users that are part of some departments.

The first step is to have a data source.  In this instance I will use a SmartObject that lists users in Active Directory that is part of the several departments.

generate a Word document from a K2 SmartForm

1 AD User K2 SmartObject

Next, create a Word template that has a table with columns for each of the users’ properties (e.g. User Name, Display Name, etc.).  Each of the columns in the table is populated with a text control from the Developer ribbon.  The key is to copy the SmartObject name in the Title textbox and the SmartObject properties in the Tag textbox.

generate a Word document from a K2 SmartForm

2 Word Template with K2 SmartObject mappings

The next part of the process is to create a OpenXml writer that maps the SmartObject Method and Properties to the controls in the document template.  Some company propriety code is in this component, but the general idea is to create client code that provides inputs to the mapping method.  This give you an idea how such a component can be created

3 Document Generation Code

3 Document Generation Code

The implementation also supports colour coding cells in the table based on data inserted into the cell.  The results are as follows –

4 Document Generated by K2 SmartObjects

4 Document Generated by K2 SmartObjects

From a design perspective, the code above is typically included in a K2 Document Generation Service Object.  This means you can generate a Word document from a K2 SmartForm by calling a K2 SmartObject wired into the K2 Service Object

5 Document Generation using K2 Service Object

5 Document Generation using K2 Service Object

About Velocity IT

We are K2 Masters.  We are at the cutting edge of K2 workflow, K2 blackpeal and K2 SmartForm development.  Our  projects are changing the way people work across various industries.  For more information, please visit our Velocity IT homepage.

Need further technical advice or support?