Date doesn't render on CSV report



  • Hi all

    I am trying to produce a csv report in js reports. I use the following code to create a template populate using the for loop. I have a function which returns todays date on js script function named "now" but when I call this function in relavant cell it doesn't render

    Js Report:

    Branch, Account Number, Sub Account Number, File Type, Created Date, Failure Reason, Extract Date
    {{for reportData}}{{:branch}},{{:accountNumber}},{{:subAccountNumber}},{{:fileType}},{{:createdDate}},{{:failureReason}}, {{:now}}
    {{/for}}
    
    function now(){
    return new Date()
    }
    

    data source:

    {
        "reportData": [
            {
                "branch": "108",
                "accountNumber": "05056210",
                "subAccountNumber": "03",
                "fileType": "M",
                "createdDate": "25 April 2024",
                "failureReason": "Load reason null"
            }
        ]
    }
    

    All other cells get populated with the respective data



  • You seem to be using jsrender and the jsrender syntax for the helper call is {{:~now()}}
    https://jsreport.net/learn/jsrender#helpers
    https://www.jsviews.com/#helpers

    Note I would strongly recommend using a handlebars templating engine. It is the most documented and supported engine in jsreport.
    https://jsreport.net/learn/handlebars



  • Thank you very much I didn't know that, still learning Js Reports.

    I can confirm syntax for the helper call worked and managed to get the date inserted in the cell.

    I consider your advise for future work.

    Thank you very much again


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.