• pega4engineers


Pega provides an interesting method to generate the word document with our case data. It basically allows you to extract data from your case, consolidate the data from the case and generate a Microsoft Word Document.

Today we are going to generate a Word document from a pre defined template which we upload into our application to fetch the case details and attach the Word document to our case.

Lets get started!

  1. To create the Word Template go to the Records explorer --> SysAdmin --> Word Template.

2. You can create the Word Template in the required class and ruleset and upload the predefined word document into Pega. You can create your own category.

3. Lets create our word document that is to be uploaded as the template. Define the required properties you need in the word document and the pega reference JSP tag so that we can fetch the value of the property that should be displayed in the document.

The JSP tag format is as: <pegaref config={"name":".propertyName","type":"P"}>

4. For example, our word template looked like this:

5. To test this we have created a simple case type with first stage to collect details and the second to generate the document.

6. We have added properties like Name, Phone, Email, Gender and Age in the Collect Submission Details Assignment.

7. In the second stage we have added a section called "Generate Document" with a button to generate the document and the case attachment section is also added for reference.

8. In the Generate Document button, Create an action set with the activity "Generate Document".

9. Lets create the Activity Generate Document. Step 1, Set the template and the document name. The Template name is the Template rule which we created initially.

10. Step 2, Call the OOTB activity "pxGenerateAndAttachDocument" which will generate the document using our template and also attach it to the case.

11. Step 3, Commit the Activity to complete and save all the processes. (Optional, Commit should be used based on your requirement)

12. Time to test!

Run the case type and enter all the details. (We have used Pega 8.6.0 version with Cosmos Theme)

Click on the generate document button. You will be able to see the document has been generated and is attached to the case.

Open the Document, Lets see if all the data is there.

You will get a message like this, trust Pega and just click "Yes".

There it is! All the data you wanted.

You can get as many properties you want from your clipboard. For example if you have a whole document defining company policies or customer data or any random thing and you need to add a few properties here and there, just pop in the JSP tags wherever necessary and create a template rule. Then use it whenever you want.