Support

Expand all | Collapse all

New to Velocity - Hierarchical headings

  • 1.  New to Velocity - Hierarchical headings

    Posted 11-24-2019 18:54
    I'm very new to Velocity and not a developer, so everything is a bit foreign. I'm trying to generate a basic context-sensitive report that will take the selected item as the top level (heading 1 in Word) and generate the tree below it with the appropriate heading indentation.

    I've done a lot fo searching and have already found the Velocity documentation (not particularly useful for a non-developer, and without descriptions of what each of the methods actually does it's hard to know which ones might be useful), lots of previous discussions with code snippets (which aren't great because I'm not sure what else I need to put in!).

    So far it seems like the best description of what I want to do is in this thread https://community.jamasoftware.com/communities/community-home/digestviewer/viewthread?GroupId=25&MessageKey=9243ee31-b8e8-4d70-aa72-2dcb0e4b31cc&CommunityKey=c9d20d4c-5bb6-4f19-92eb-e7cee0942d51&tab=digestviewer but I get lost at this statement:

    Any other items should spin through this, using the $start variable above.
    #getIndentCount( $documentNodeDao.getDocumentNode(5, $doc.id).sequence)

    #set( $docNodeIndent = $getIndentCountReturn)

    #set ($indentCount =  $mathTool.toInteger($docNodeIndent) - $mathTool.toInteger($start) + 1)

    What does "all other items should spin through this" mean? Where does that code go? I've tried it after the #foreach($doc in $documentList) bit, but that doesn't seem to work.

    All the examples in GitHub are at a project level (as far as I could tell), so working out what extra bits I need for a context sensitive report is difficult!

    Thanks in advance for any help at all!​​

    ------------------------------
    Julie Kalitis
    SITA
    ------------------------------


  • 2.  RE: New to Velocity - Hierarchical headings

    Posted 12-02-2019 08:08
    Hi Julie:

    Try using this: 

    #########################################################################################################################

    ## Helper: Returns a source with a new cid and appends the base64 image to the end of the file     ###

    ## @sequence - array: documentnode Sequence           ###

    ## @return - array: returns an array of strings of the new image src   ###

    #########################################################################################################################

    #macro( getIndentCountMHTML $sequence )

    #set( $getIndentCountMHTMLReturn = 0)

    ##Get count of dots in starting node

    ##set( $sequence = $documentNodeDao.getDocumentNode(5, $doc.id).sequence)

    #set( $seqCount = 0)

    #set( $lastDot = $sequence.lastIndexOf("."))  ##>

    #set( $st = $sequence.indexOf(".")) ##>

    #foreach( $x in [$st..$lastDot])

    #if( $x == $sequence.indexOf( ".", $x))  ##>

    #set( $seqCount = $seqCount + 1)

    #end

    #end

    #set( $getIndentCountMHTMLReturn = $seqCount)

    #end

    ####################################################################################################################

    #foreach( $doc in $documentList)

    #set( $doc = $vDoc.document)

    #if( $iCounter == 0)

    #getIndentCountMHTML( $documentNodeDao.getDocumentNode(5, $doc.id).sequence)

    #set( $start = $getIndentCountMHTMLReturn)

    #set( $iCounter = 1)

    #end

    #getIndentCountMHTML( $documentNodeDao.getDocumentNode(5, $doc.id).sequence)

    #set( $docNodeIndent = $getIndentCountMHTMLReturn)

    #set ($indentCount =  $mathTool.toInteger($docNodeIndent) - $mathTool.toInteger($start) + 1)

    #if( $indentCount == 1)

    <div style=3D'mso-element:para-border-div;border:none;border-bottom:solid windowtext 1.0pt;

    mso-border-bottom-alt:solid windowtext .5pt;padding:0in 0in 1.0pt 0in;

    margin-left:4.5pt;margin-right:0in'>

    <h$indentCount style=3D'mso-list:l19 level$indentCount lfo2'>$doc.name</h$indentCount>

    </div>

    $!doc.description

    #elseif( $indentCount < 7 && $indentCount > 1)

    <h$indentCount style=3D'mso-list:l19 level$indentCount lfo2'>$doc.name</h$indentCount>

    $!doc.description<br>

    #else

    <p class=3DMsoHeading$indentCount>$doc.name</p>

    $!doc.description<br>

    #end

    #end

    Collapse




    Best,



    ------------------------------
    Chloe Elliott
    Jama Software
    Portland OR
    ------------------------------



  • 3.  RE: New to Velocity - Hierarchical headings

    Posted 12-05-2019 18:47
    Hi Chloe,

    Thanks for this, but I still can't get it to work. This prints "$doc.name" for each item in the list rather than the actual document details. I've tried using a really plain document template without all the word styles just in case that was interfering, but the same outcome. This is the full text of the file with the html tags in place:

    ##################################################################################################################################################################################################################################################
    ## Helper: Returns a source with a new cid and appends the base64 image to the end of the file     ###
    ## @sequence - array: documentnode Sequence           ###
    ## @return - array: returns an array of strings of the new image src   ###
    #########################################################################################################################
    #macro( getIndentCountMHTML $sequence )
    #set( $getIndentCountMHTMLReturn = 0)
    ##Get count of dots in starting node
    ##set( $sequence = $documentNodeDao.getDocumentNode(5, $doc.id).sequence)
    #set( $seqCount = 0)
    #set( $lastDot = $sequence.lastIndexOf("."))  ##>
    #set( $st = $sequence.indexOf(".")) ##>
    #foreach( $x in [$st..$lastDot])
    #if( $x == $sequence.indexOf( ".", $x))  ##>
    #set( $seqCount = $seqCount + 1)
    #end
    #end
    #set( $getIndentCountMHTMLReturn = $seqCount)
    #end
    ####################################################################################################################
    <html>
    <head>

    <title>Test</title>  </head>  <body>

    ## @return - array: returns an array of strings of the new image src   ############################################################################################################################
    #macro( getIndentCountMHTML $sequence )

    #set($getIndentCountMHTMLReturn = 0)
    ##Get count of dots in starting node ##set($sequence = $documentNodeDao.getDocumentNode(5, $doc.id).sequence) #set($seqCount = 0)
    #set($lastDot = $sequence.lastIndexOf("."))  ##>
    #set($st = $sequence.indexOf(".")) ##>
    #foreach($x in [$st..$lastDot]) #if($x == $sequence.indexOf( ".", $x))  ##>
    #set($seqCount = $seqCount + 1) #end #end #set($getIndentCountMHTMLReturn = $seqCount) #end
    ####################################################################################################################

    #foreach($doc in $documentList)
    #set($doc = $vDoc.document)
    #if($iCounter == 0)
    #getIndentCountMHTML($documentNodeDao.getDocumentNode(5, $doc.id).sequence)
    #set($start = $getIndentCountMHTMLReturn)
    #set($iCounter = 1)
    #end

    #getIndentCountMHTML($documentNodeDao.getDocumentNode(5, $doc.id).sequence)
    #set($docNodeIndent = $getIndentCountMHTMLReturn)
    #set ($indentCount =  $mathTool.toInteger($docNodeIndent) - $mathTool.toInteger($start) + 1)
    #if($indentCount == 1) <div style=3D'mso-element:para-border-div;border:none;border-bottom:solid windowtext 1.0pt; mso-border-bottom-alt:solid windowtext .5pt;padding:0in 0in 1.0pt 0in; margin-left:4.5pt;margin-right:0in'> <h$indentCount style=3D'mso-list:l19 level$indentCount lfo2'>$doc.name</h$indentCount> </div>

    $!doc.description

    #elseif($indentCount < 7 && $indentCount > 1)
    <h$indentCount style=3D'mso-list:l19 level$indentCount lfo2'>$doc.name</h$indentCount> $!doc.description<br>
    #else
    <p class=3DMsoHeading$indentCount>$doc.name</p> $!doc.description<br> #end#end

      </body></html>

    ------------------------------
    Julie Kalitis
    SITA
    ------------------------------



  • 4.  RE: New to Velocity - Hierarchical headings

    Posted 6 days ago
    Hi Chloe,

    I'm working with Julie on this problem and I wanted to confirm that the start of your code is still valid for the upgraded version of Velocity?

    #foreach( $doc in $documentList)

    #set( $doc = $vDoc.document)

    I'm not sure the document is being properly picked up and wonder if this needs to be changed to something involving DocumentSource as mentioned in the latest Velocity API guide?

    Regards

    Alistair



    ------------------------------
    Alistair McBain
    SITA
    ------------------------------



  • 5.  RE: New to Velocity - Hierarchical headings

    Posted 6 days ago
    Alistair:

    I can confirm that the code is fine. Are you NOT getting anything in the documentList?

    Best,

    ------------------------------
    Chloe Elliott
    Jama Software
    Portland OR
    ------------------------------



  • 6.  RE: New to Velocity - Hierarchical headings

    Posted 3 days ago
    Hi,

    If I put a $doc.name after the first two lines, all I get on the screen is $doc.name. Which made me wonder if it was empty? Or perhaps I am using the wrong command. How would I check that the documentList has been populated?

    #foreach( $doc in $documentList)

    #set( $doc = $vDoc.document)

    $doc.name

    Regards

    Alistair

    ------------------------------
    Alistair McBain
    SITA
    ------------------------------



  • 7.  RE: New to Velocity - Hierarchical headings

    Posted 2 days ago
    Hi Alistair:

    Your first line should be:  #foreach( $vDoc in $documentList)

    vDoc was never set.

    Best,


    ------------------------------
    Chloe Elliott
    Jama Software
    Portland OR
    ------------------------------