Support

 View Only
  • 1.  dateTool in VTL

    Posted 10-02-2023 23:39

    Hello I am trying to automate the year in my velocity code, I saw that we can use the dateTool but unfortunately I tried to use it but whenever I print out the year it prints the variable name such as $year it seems dateTool is not supported, how can I solve this issue ?



    ------------------------------
    Mohamed Smaili
    Clever Circuits
    ------------------------------


  • 2.  RE: dateTool in VTL

    Posted 10-03-2023 02:42

    Hi Mohamed,

    have you tried something like this?

    #set( $org_date = "")
    #set( $year = "")
    ## add your code here to get the $org_date. If it is e.g. a field in an item, you can use something like this:
    #set( $org_date = $velocityReportUtil.getValueForField($doc, "completion_date", $dateFormat))
    ## then use dateTool to get the year:
    #set( $year = $dateTool.toDate('yyyy', $org_date))

    I haven't tried it so I can't say for sure if this works.



    ------------------------------
    Patrick
    ------------------------------



  • 3.  RE: dateTool in VTL

    Posted 10-03-2023 02:56

    Hello Patrick, the thing is that the year is not a field in an item I must automate it to read the year and update it accordingly if you got my point.



    ------------------------------
    Mohamed Smaili
    Clever Circuits
    ------------------------------



  • 4.  RE: dateTool in VTL

    Posted 10-03-2023 05:43

    Can you provide a concrete example what you try to achieve? And maybe the code you tried?



    ------------------------------
    Patrick
    ------------------------------



  • 5.  RE: dateTool in VTL

    Posted 10-03-2023 05:57

    I need to insert the the current year in the footer in excel using a velocity code. The code that I was trying to use is his

    #set($dateTool = $tool.date)

    #set($currentDate = $dateTool.date())

     #set($year = $dateTool.getYear($currentDate))

    But unfortunately this piece of code is not giving any output I tried to print out in excel every single variable in this code but it kept on printing a $ sign and variable name.



    ------------------------------
    Mohamed Smaili
    Clever Circuits
    ------------------------------



  • 6.  RE: dateTool in VTL
    Best Answer

    Posted 10-03-2023 06:29
    Edited by Carly Rossi 10-03-2023 15:29

    You can simply use $dateTool.get('yyyy') for that. I tried it in a footer and it worked.

    You don't need this line for that.

    #set($dateTool = $tool.date)

    ------------------------------
    Patrick
    ------------------------------



  • 7.  RE: dateTool in VTL

    Posted 10-03-2023 06:46

    So I only insert the $dateTool.get('yyyy') in the footer and it must show up the year ?



    ------------------------------
    Mohamed Smaili
    Clever Circuits
    ------------------------------



  • 8.  RE: dateTool in VTL

    Posted 10-03-2023 07:12

    exactly



    ------------------------------
    Patrick
    ------------------------------



  • 9.  RE: dateTool in VTL

    Posted 10-03-2023 07:50

    I tried it and it worked, Thank you Patrick for your help. If you could also please help me out in the problem regarding to insert an image in the header it would be very appreciated.



    ------------------------------
    Mohamed Smaili
    Clever Circuits
    ------------------------------