Question
Capgemini
CA
Last activity: 4 Oct 2018 13:54 EDT
Generate word document using word document, which can show data from page list, table format dynamically
Hi Everyone,
We are using 7.1.8, we want to generate word document which can show content from complex page list.
Can any one guide me to achieve below.
For e.g.: let's say we have a structure
Organization
Departments (Repeating)
Employees (Repeating)
We want to generate document like below.
1. Organization
1.1 HR
Employees
Name | Mobile | Address | Manager | |
---|---|---|---|---|
Employee Name 1 | [email protected] | 999999999 |
Employee Name 1, Address |
Hi Everyone,
We are using 7.1.8, we want to generate word document which can show content from complex page list.
Can any one guide me to achieve below.
For e.g.: let's say we have a structure
Organization
Departments (Repeating)
Employees (Repeating)
We want to generate document like below.
1. Organization
1.1 HR
Employees
Name | Mobile | Address | Manager | |
---|---|---|---|---|
Employee Name 1 | [email protected] | 999999999 |
Employee Name 1, Address |
Manager 1 |
Employee Name 2 | 888888888 |
Employee Name 2, Address |
Manager 2 |
1.2 Admin
Employees
Name | Mobile | Address | Manager | |
---|---|---|---|---|
Employee Name 1 | [email protected] | 999999999 |
Employee Name 1, Address |
Manager 1 |
Employee Name 2 | 888888888 |
Employee Name 2, Address |
Manager 2 |
I also need to attach dynamic images dynamically from work objects.
Please suggest.
**Moderation Team has archived post**
This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Updated: 10 May 2016 7:10 EDT
Hi Satya,
It should generate the document with image. I suspect you might have added few spaces in the Pega:corr and corr name.
Please find working example as an attachment and make changes according to your requirement (check rule set prerequisites after the import). I have created an activity in the RS, run that activity it gives you URL.I have tested and it is inserting image. Let me know if you stuck at something or You can contact Pega support they will help you.
Thanks.
Infosys
AU
Is your requirement to generate this word document at client side by launching word application? If so, you can write custom HTML to generate the data as per your format - just need to iterate over embedded page lists and format the data in tabular content.
For example, pzDocumentChapters is one of the OOTB custom HTML rules used in Pega to generate Application Document and it has following custom code:
<html>
<pega:forEach name=".pyChapters">
<pega:when test='$this.pyIncludeInDoc == "true"'>
<p><span style="mso-element:field-begin"></span>
pega:insert corr="pzDocumentTopChapter"
<span style="mso-element:field-end"></span></p>
</pega:when>
</pega:forEach>
</html>
Here pyChapters is the page list.
With this approach you can include other field codes to insert images from work objects as well.
Or you can try this directly in Correspondence rule as well but I feel custom HTML is easier.
Hope this helps you!
Murali...
Capgemini
CA
Hi Murali,
Since we are using Pega 7.1.8, we are looking for a solution for server side.
Thanks,
Satya
Infosys
AU
I am not sure if server side word generation feature is available for customers to use. Vinay Kadiam, could you please confirm this?
Thanks,
Murali
Hi Murali,
Yes, server side document generation is available from Pega 7.1.8.
Satya,
We do not have OOTB chapter to solve your use case. But we can achieve this by creating few rules.
You can follow below steps.
1. create a section rule with below code.
<html>
//Document org name
<%
tools.appendString( "<h1>" );
tools.appendString( OrgName);
tools.appendString( "</h1><br/>" );
%>
//iterate over Departments using iterator
<pega:forEach name=".Departments">
<%
tools.appendString( "<h2>" );
tools.appendString(DepartmentName);
tools.appendString( "</h2><br/>" );
%>
//Append Employees label
tools.appendString("Employees");
//Iterate over Employees using iterator
<pega:forEach name=".Employees">
//Create the employees table
//Write your the HTML code to get the required table
</pega:forEach>
</pega:forEach>
</html>
But for inserting images, you need to use below tag for inserting the images.
<PegaDocumentObject>Your image Key(InsKey of the rule)</PegaDocumentObject>
Hi Murali,
Yes, server side document generation is available from Pega 7.1.8.
Satya,
We do not have OOTB chapter to solve your use case. But we can achieve this by creating few rules.
You can follow below steps.
1. create a section rule with below code.
<html>
//Document org name
<%
tools.appendString( "<h1>" );
tools.appendString( OrgName);
tools.appendString( "</h1><br/>" );
%>
//iterate over Departments using iterator
<pega:forEach name=".Departments">
<%
tools.appendString( "<h2>" );
tools.appendString(DepartmentName);
tools.appendString( "</h2><br/>" );
%>
//Append Employees label
tools.appendString("Employees");
//Iterate over Employees using iterator
<pega:forEach name=".Employees">
//Create the employees table
//Write your the HTML code to get the required table
</pega:forEach>
</pega:forEach>
</html>
But for inserting images, you need to use below tag for inserting the images.
<PegaDocumentObject>Your image Key(InsKey of the rule)</PegaDocumentObject>
2. Create a correspondence rule and include above created section.
3. Create a word template and insert above created correspondence rule in the word template or if the requirement is to edit an existing word tmeplate modify exsting word template rule by adding created corr rule.
4. Write an activity and call the RUF pzGenerateDocument which will give you URL of the generated document. Please have a look at pzDocumentNow activity for the help.
Let us know if you are having any trouble in generating word document we will try to help you.
Regards,
Vinay
Capgemini
CA
Hi Vinay
I tried to follow your suggestion, I created a section and for now I have just tried to include below code in it.
<html> <p>Test before Doc</p>
<PegaDocumentObject>RULE-FILE-BINARY WEBWB PYMENULEFTARROW!PNG #20150501T182533.856 GMT</PegaDocumentObject>
</html>
Now I have included this section in correspondence and created a word template with below field codes.
{pega:reference .pyNote}
{pega:insert corr=IncludeImage}
Now, when I am generating Document. It is only showing the text from .pyNote, but nothing from corr.
Do you think, I am doing any thing wrong here.
Accepted Solution
Updated: 10 May 2016 7:10 EDT
Hi Satya,
It should generate the document with image. I suspect you might have added few spaces in the Pega:corr and corr name.
Please find working example as an attachment and make changes according to your requirement (check rule set prerequisites after the import). I have created an activity in the RS, run that activity it gives you URL.I have tested and it is inserting image. Let me know if you stuck at something or You can contact Pega support they will help you.
Thanks.
Capgemini
CA
Hi Vinay/ Murali,
Thanks a lot for your Vinay Kadiam and Murali Kakarla time and help. Your suggestions did work.
There was some issue in the application instance I was working on. In a different instance it worked just fine.
I need some more information, if you can help.
I have included fieldcode for TOC. But while opening the document, it is asking user to click Yes to update the field codes as below.
Is there a way to avoid this dialogue and still show the updated TOC in the word.
Also is there a way to control the CSS. Like color of header tags like h1... or any other CSS we want.
Thanks
Satya
Hi Satya,
We can not avoid that dialog as it generates the TOC when we open the doc file. On click of Yes will generate the TOC.
You need to write styles in the HTML rule and include it in the section. Please have a look at pyAppDocStyle and its referenced rules.
Regards,
Vinay
Capgemini
CA
Thanks Vinay Kadiam,
I am able to generate document, how ever while including the contents from rich text editor into word, any images uploaded into the rich text editor are not showing in the document. Below is how it is appearing. Do you have any suggestions for this.
Thanks,
Satya
Yes, it will not include them as we have some dependency with the Docx4j. If you want to include a image in the document, you should use PegaDocumentObject tags otherwise we will not include them in the generated document.
For reference, look at
pyImplementationApproach(section) --> pyImplementationApproachNew(Paragraph) --> pyImplementationApproachPegaLed(section) --> pzInsertDocumentObject(Section).
pzInsertDocumentObject takes ins key of the image as parameter and inserts required tags for inserting image in the document.
Updated: 17 May 2016 4:14 EDT
Capgemini
CA
Hi Vinay Kadiam,
But when we use {pega:reference .RTEField} directly with in word template, where RTEField is mapped to Rich Text Editor and generate the document, pega is able copy images with in rich text editor into word.
Can you think of any approach where we can copy images from RTE into word generated. This is very critical for our requirement.
Or is there a way to generate pzInsKey when uploading image into RTE.
Thanks,
Satya.
Coforge
IN
Hi Vinay,
I have imported the jar and tried with {pega:reference .PropertyName}. but it's not working.
But when I tried {pega:insert corr=CorrName} its working.
Can you please help on this.
Additional to this is it possible instead of generating URL can we attach the Word Document to Case.
Thanks.
Pegasystems Inc.
GB
There is an example here showing how to create a Word (2003 XML format) file using Pega Tags: https://mesh.pega.com/message/178125#178125
Pegasystems Inc.
GB
Actually: I just re-checked it: the example only gives the static XML needed to generate a basic WORD document: but you can mix-in some Pega JSP tags in there to generate dynamic content as well.
Capgemini
CA
Thanks for your time John.
Vinays suggestions worked for me.
Regards,
Satya
AdeptView
NL
Hi All,
I am working on similar requirements where I have to generate word document from a Word template.
I am trying to create Word Document using pzGenerateDocument RUF (as per Vinays' solution).
I am facing one problem, If I do a property reference for eg: {pega:reference .PropertyName} directly in the WordTemplate, I am not getting any value.
But If I refer same property inside the Corr rule then I can see the Value. (See the attached SS)
Note: {pega:insert corr=CorrName} is working
{pega:reference .PropertyName} is not working
Am I missing anything here? Need your Kind Help!!
Thanks in Advance
-
KARTHIKA R
Pegasystems Inc.
IN
This is being pursued as a new discussion: Getting empty values when referencing a property directly in Word Template
Aaseya IT Services Pvt. Ltd.
IN
I am successfully able to generate and download the word document by generating it with the function com.pegarules.generated.pega_appdefinition_documentapp.pzGenerateDocument
Additionally I have a requirement to attach the word document to a Pega case. The url string returned by the function com.pegarules.generated.pega_appdefinition_documentapp.pzGenerateDocument contains * for which Pega Engine APIs to instantiate a PRFIle type object is throwing runtime exceptions.
Also tried with the standard java function new java.net.URL() but unable to create (object null) any URL object from the url string.
If someone has implemented this sort of a requirement kindly suggest.
Pegasystems Inc.
IN
Hello,
We see that you have created a new post for this query: Generate MS Word Doc and Attach To Case
Good work!
Regards,
Coforge
IN
Hi,
Even for me also property reference not working.
{pega:insert corr=CorrName} is working
{pega:reference .PropertyName} is not working
Thanks
Pegasystems Inc.
IN
Hello,
I see that you have added the same reply on the newer post: Generate MS Word Doc and Attach To Case
Regards,