Usage of Runtime template in document generation

Certified Senior Developer

Hi All,

I'm facing an issue while generating a document using runtime templates. There is no specific error as such. I'll brief my issue for better understanding.

I'm using an Appian smart service "MS Word 2007 Doc from Template" for document generation. I have created 2 different templates "SWO Templates Type1" and "SWO Templates Type2" (attached for reference)  which needs to be selected at runtime. As a result I have used runtime template to select required templates at run time. The expression used for selecting run time template is given below.

=todocument(if(pv!SPM_CDT.swoType="Add DB2 Storage Groups",'cons!SPM_Document_Type1','cons!SPM_Document_Type2'))

cons!SPM_Document_Type1 --> contains document ID of SWO Templates Type1

cons!SPM_Document_Type2 --> contains document ID of SWO Templates Type2

Base template "SWO Templates" has also been created. (attached for reference).

Problem here is, based on the runtime template expression it is being evaluated to the right document, but no values are being passed to any template.

However, I tried testing all 3 templates by running it separately, it all ran fine. There seems to be a problem when I'm using runtime template.

Not very sure, is there any issue with base template or runtime templates or runtime templates expression.

Can you please help us in identifying the issue here?

Please let me know if any more information is required.

SWO Templates.docxSWO Templates Type1.docxSWO Templates Type2.docx

Thanks

Beena V 

 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I've checked the background XML in all 3 of your documents.  From what I can tell, you *should* be able to correctly generate documents using SWO Templates Type1, but in the Type2 document, you will run into issues with certain replacement keys due to an old unfixed bug in the Docx from Template smart service (as described here).  And even in that case I would expect some of the replacement fields to work -- if none of them work, then you probably need to keep troubleshooting the syntax of your runtime template document picker box.

    Can you double-check whether you're able to get *any* replacement fields working, for example, with the Type1 template?  (For troubleshooting, you might want to start out with JUST template Type1 being passed in to the runtime field, instead of your current logic, in case there is some syntax mistake there).

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt
    Hi Mike,

    Thanks for the reply. In both Type 1 and Type 2 documents, only ###name### is getting evaluated properly. None of the other keys in the document are getting values. In order to check any syntax error, I even tried using 1 template at a time instead of evaluating at runtime. All 3 documents generated successfully with values for all substitution keys.

    When I use runtime template document picker box, it evaluates to right template but values are not being passed except ###name###.

    Any advise on this?

    Thanks
    Beena V
  • 0
    Certified Lead Developer
    in reply to Beena Venugopal
    I'm surprised ###name### is getting replaced properly but no others.
    One thing I'd like you to try real quick, please: open the smart service node, to the "Setup" tab, and click "Re-Scan Template"... and make sure all the values are still populated after that. Sometimes when there's an issue with the XML code underlying the replacement keys in the template file, and a new version has been uploaded with some incompatibility introduced, the inputs will get cleared out when you try this.
  • 0
    Certified Lead Developer
    in reply to Beena Venugopal

    Also I just noticed that even though many of your replacement keys are the same, you have replacement keys in the template that are not in Type 2, and some in the template that are not in Type 1.  I believe in the Smart Service configuration it warns that the replacement keys must match exactly between the different documents used for this purpose -- meaning all replacement keys must match in a 1:1 fashion between the different templates you're using.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt
    Thanks . Sorry for the late reply :)

    Yes Mike 2 templates should have similar replacement keys. But along with it, it can also have extra replacement keys which are not common in both.

    However, I tried deleting both the templates and created similar templates again ( as before). Then I could able to see all the replacement keys worked properly.

    There seems to be an issue with docx template.
  • 0
    Certified Lead Developer
    in reply to Beena Venugopal
    If you have templates with keys that are not common in both, then I believe whichever template you're using as the "master" must include all keys used in any of the others. If you don't have a "master" template that contains all keys, you should probably make one which *just* includes keys.

    I'm not sure if the relative ordering of the keys (as mentioned) actually matters - I believed it wouldn't matter - but you should be able to confirm this with a simple test.

    I'm mainly concerned that the keys are rendering differently between your different document versions, due to the XML issue I mentioned previously - which is invisible when viewing through Word. If you open up the document.xml contained inside your .docx file, you should be able to find the replacement key text and make sure there is no xml breaking up the string of "###keyName###" - because if this is different between the master template and the runtime template, my worry is that the runtime template won't work correctly since Appian won't recognize that the keys match.
  • 0
    Certified Senior Developer
    in reply to Mike Schmitt
    Hi ,

    Yes, My master template includes all the keys present in both Type1 and Type2 templates (run time templates).

    Yes this is a XML issue. I tried comparing document.xml of both Type1 and Type2 templates, there is mismatch in the order of the values being passed in XML tags. This clearly conveys an XML issue.

    The way to fix this is to recreate the docx template again n check whether is there any issue with XML or I just manually fix the XML issue or is there any other way?

    Thanks for the suggestion Mike.

    Regards
    Beena V
  • 0
    Certified Lead Developer
    in reply to Beena Venugopal
    Hi,

    The mismatch I'm expecting you to see is not really about the order of the replacement keys, but that in some cases the text for the replacement keys might be broken up with other XML code by Word, in a way you can only see if you look at the word XML file as you've done. From your response it sounds like this is what you looked for but i'm not 100% sure. Also in the past I've found that if you look at the smart service node properties in the process model "documentation" view, the replacement keys will look differrent in that view to how they look in the smart service node.

    There are 2 ways I know of to correct this issue:

    First, you can correct the replacement keys manually inside the document.xml file and then replace the existing one with the "fixed" version in the zip file of the word document. To do this you would simply need to cut and paste one of the separate halves of the replacement key into the xml text field with the other half, in such a way that they're together again.

    Second, you can try deleting and re-typing the replacement key in Word itself. VERY IMPORTANT, turn OFF all spell checking and grammar checking first, because these tools are what cause the random XML elements to become interspersed in the middle of contiguous text like replacement keys, in the first place. This is a good idea to do in general when working with word documents with replacement keys, at least until Appian sees fit to fix this bug. I should note that sometimes deleting and re-typing the key will work, and sometimes it won't, at which point you might want to resort to editing the XML file directly.
  • 0
    Certified Senior Developer
    in reply to Mike Schmitt
    Thanks

    I have tried editing the XML itself, it worked (y).

    I have even tried removing the replacement keys and re-typing it again. As you said, it works sometimes and sometimes it won't.

    Thanks for your suggestions (y).
Reply Children
No Data