Hi All, I was trying to use the Advanced Document Templating to gene

Hi All,

I was trying to use the Advanced Document Templating to generate a word document for the data queried from Query Database. This is my query:
SELECT
          
projectname
,activitycategory
,activitydescription
,activitytype
,type
,updatedate

FROM ptcprojectupdate
INNER JOIN ptcupdate on ptcprojectupdate.ptcupdate_projectupdates_a_id = ptcupdate.a_id

Where ptcprojectupdate.projectname = ac!project


After running this query, I put everything into a grid in an email using the "ncolumntable" function (see attachment AppianQ18).

Now, I want to put the data into a word document instead of putting into the grid in an email.

However, I have some trouble defining the structure of my template and mapping my pv (s) into the grid. I have attached my template and Xml data input data part (I just tried one variable "project").

Can someone take a look and let me know where I did wrong? Any help would be much appreciated....

ADT Question.zip

OriginalPostID-147532

OriginalPostID-147532

  Discussion posts and replies are publicly visible

  • sorry, I misunderstood the question. so you are already using this smart service. as per documentation the XML Data Model is a string like
    ="<project>
    <name>This is a simple placeholder</name>
    <developer name='John' lastEmail='Smith' mail='smith@email' day='10-10-2014' />
    <developer name='Frank' lastEmail='Brown' mail='frank@email' day='10-10-2014' />
    </project>"
    first of all your PV assignment does not look right. second, make sure the pv value is correct XML structure.
  • @venkats533 thanks very much for your comments! That's exactly I was confused about. How do I get my pv assignment right and how can I connect my pv value in XML structure. Can you give me an example? The guide is not very clear to me and I didn't see some relevant questions in the forum on pv assignment and how to write the XML structure. Any help or guidance would be very much appreciated.

    Thanks a bunch in advance!
  • 0
    Certified Lead Developer
    I have some expreience creating an arbitrary table within a Word document. In my case, the advanced document templating plug-in was either unavailable or not invented yet.

    To get a table to work in Word, what I had to do was format the desired data into WordML (word's special XML) and insert the resulting text into the regular "Word Document from Template" smart service. Included in this was figuring out the code for a table and creating the XML for that; I used a series of expression rules. (at first glance in the ADT plug-in, it looks as if the user is expected to create the table XML themselves there, too). So I'm not sure what the best answer would be in your case, but I'm guessing it may require creating XML structure.
  • Hi Lin Shi,
    Please have a look below. I've explained how to implement is and provided with an example. I've not tested the expressions written below as I've just written them.
    Let me know if it solves your issue.

    Output of the query (array of type!projectname):
    ={
    {activitycategory:"ac1", activitydescription:"ad1", activitytype:"at1", type:"t1", updatedate:"u1"},
    {activitycategory:"ac2", activitydescription:"ad2", activitytype:"at2", type:"t2", updatedate:"u2"}
    }


    XML correspondent to the output of the query (this will be the output of the rule for generating XML):
    <project>
    <projectname activitycategory='ac1' activitydescription='ad1' activitytype='at1' type='t1' updatedate='u1'/>
    <projectname activitycategory='ac2' activitydescription='ad2' activitytype='at2' type='t2' updatedate='u2'/>
    </project>


    Main rule for generating a dynamic XML:
    rule!mainRuleXml(ri!arrayOfProjectName):
    =with(
    local!arrayOfXmlTagProjectName:joinarray(apply(rule!generateXmlTagFor1Row, ri!arrayOfProjectName), " "),
    "<project>" &
    local!arrayOfXmlTagProjectName
    & "</project>"
    )

    Sub Rule:
    rule!generateXmlTagFor1Row(ri!currentProjectName):
    =""<projectname activitycategory='" & toHtml(ri!currentProjectName.activitycategory) &
    "' activitydescription='" & toHtml(ri!currentProjectName.activitydescription) &
    "' activitytype='" & toHtml(ri!currentProjectName.activitytype) &
    "' type='" & toHtml(ri!currentProjectName.type) &
    "' updatedate='" & toHtml(ri!currentProjectName.updatedate) & "'/>"


    fn!joinarray is used to convert an array of string XML tags in just one string XML
    fn!toHtml is used to convert in HTML code special chars that can be in the array of CDT and interfhere with the XML definition (such as the char &)
    I suggest you to follow these steps for the development:
    1. Use the xml example that I provided you to verify that the docx is actually working fine
    2. Implement the rules for the dynamic XML generation and use it instead of the XML sample
  • Hi Corrado, thanks so much for explaining this-I really appreciate this. While I was trying to put the info. into the right box, I wonder if I should create a "Custom Output" in the data tab of the Query Database (see attached)?
    Where should I put for the rule and the sub rule you were mention.
    Again, thank you very much and appreciate your guidance!