29 Jul 2019

Doc Auto - Velocity library

This article provides examples of Velocity code that you can use with Document Automation ('Doc Auto') templates. 

Doc Auto template syntax

To create the template needed for Document Automation, open the template in Microsoft Word. You should already have syntax similar to the image below.

 

To edit the fields go to the left of each line and right-click, as shown in the image below. Choose Edit Field

The Field window displays.

The field name needs to be updated to reflect the information that needs to be added.

You need to enter the characters exactly as they are displayed, with the same casing.

Each section of information should be added in between the two apostrophes e.g. 'comments I have added'. For example:

#set($sheetTitle='Enter your sheet title here')

#set($viewName='Enter the view here e.g. Default')

#set($map={"c1":"Enter the lookup column name here||enter the name of the first column you want to lookup here"})

$!{map.put("c2","Enter the lookup column name here||enter the name of the second column you want to lookup here")}

$!{map.put("c3","Enter the lookup column name here||enter the name of the third column you want to lookup here")}

#set($fieldsMap=$utils.getSheetDocReportDataMap( $sheetTitle,$viewName,$map))

#foreach($key in $fieldsMap.keySet())

#set($innerMap=$fieldsMap.get($key))

#foreach($innerKey in $innerMap.keySet())

$innerMap.get($innerKey)

#end

#end

Once you have added the required information it should look like this:

The highlighted areas in the example above should contain your own references.

The || (double pipe sign) indicates a lookup column (the two examples, 'c1' and 'c2' in the image above). The 'c3' line in the example above references a single line text column, so does not need to include a ||. In this example, the lookup columns are from another iSheet, selected when you created the lookup column in the iSheet. 

To remove a line from the syntax (for instance, a column because it's not needed) just highlight the line and delete it.

To add a line into the syntax, copy a line already in the syntax, click at the end of the row above where you want to add the line and tap enter. Select Insert, click on the Quick Parts icon (1) , Field (2), and then Insert Field (3). Paste the copied line and change c1 to the next column number, depending on how many are in the list e.g 2, 3. Click OK to save the update. 

Save your document.

Manage document templates

Navigate to Admin > iSheets to see the main iSheets view. Click Manage document templates to add a Word file as a document template.

Click Add template, then enter a template name, choose the radio options for Site wide template or Single record template and then Browse to add the Word document. In the Document automation settings of the Add template window, you can choose how your document is generated and choose settings for saving and downloading the file. Click Save to add your template to the Manage document templates listing. 

To use the lookup template you will need to access the iSheet and use the Doc Auto (or Generate document) option. Go to iSheets from the site navigation bar and then select your iSheet from the listing. 

In the More actions option choose Doc Auto (renamed Generate document on some instances). 

The Document templates window displays. Select the template that includes the lookup column and click Generate. The document is displayed as defined in settings (either Word or PDF) and includes the lookup columns requested in the Edit Column window. 

Was this article helpful?