reportName not working. Reports are stored with random name.



  • Hi, I was testing the jsreport with node.js and express. I am able to render a report as expected. I have mentioned the reportName in the options of jsreport.render() but still reports are stored with random name.

    jsreport.render({
    template: { name:'driver-manifest-main'},
    data: req.body,
    "options": {
    "reportName": req.body.docId,
    "reports": { "save": true }
    }
    }).then((resp) => {
    logger.info('Processed the driver manifest generation request');
    res.send({"msg":"successful"})
    }).catch((e) => {
    logger.error('Error occurred while processing driver manifest generation request ' + e.toString());
    res.send({
    "statusCode": 500,
    "errorMessage": e.toString(),
    "timestamp": Date.now()
    })
    });



  • I apologize, this is a bit misleading in the docs.

    The name of the stored file/blob is by default inherited from the entity unique _id. This can be customized using { "options": { "reports": { "save": true, "blobName": "myfilename" } }

    So your request should look like this

    {
      "template": { "name":'driver-manifest-main'},
      "data": req.body,
      "options": {
        "reports": { "save": true, "blobName": req.body.docId }
      }
    }
    


  • oh great, thanks for the help :D



  • How can I mention the directory where to store the generated reports?



  • This can be only done globally. Using this config

    "blobStorage": {
    	"provider": "fs",
    	"dataDirectory": "myblobslocation"
    }
    


  • In the global config, I can mention the root folder and that's great. But my requirement is slightly different, I want to store the reports in different folders based on each request. So, I may want to store all the pdf reports of one day into a folder with that date. I want the same behavior for the azure blob storage.



  • Ok. In that case, you can pass the path as part of the blob name.

    {
        "template": { "name": "a" },
        "options": { "reports": { "save": true, "blobName": "adirectory/foo" } }
    }
    

    You just need to make sure that the directory exists. Probably using the beforeRender hook.
    You may also dynamically assemble the path there.
    https://jsreport.net/learn/scripts

    const fs = require('fs')
    
    function beforeRender(req, res) {
      const date = new Date().toISOString().substring(0, 10)
      req.options.reports.blobName = date + '/' + req.template.name
      fs.mkdirSync('data/storage/' + date)
    }
    


  • Great. Thanks for the help :D


Log in to reply
 

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