New to JSReport and Tutorial isn't working



  • HI !
    I am new to jsreport and I only start to download it yesterday. I am using this page as reference: https://jsreport.net/blog/pdf-reports-in-sql-server

    so I can get data from database, however the document is blank and I got this :
    0_1529912896125_upload-8ffb243d-78df-4617-9135-6ced6577f00a

    here is my code (I'm not really changing it):
    0_1529913133363_upload-8e202f24-64a1-4e7c-859e-de4058dfe7db

    0_1529913235365_upload-e9275f0b-8faf-43a5-90cd-ec6d930761a4

    This is really stressed me out... please help me..
    Am I doing something wrong here ?



  • Hi,

    there are some breaking changes in jsreport v2 which were not propagated to that blog post.
    I tried to update it now.

    The main difference is that the scripts beforeRender function has different signature.
    This should work.

    const sql = require('mssql');
    const config = {
        "user": "jsreport",
        "password": "password",
        "server": "janblaha-PC\\SQLEXPRESS",
        "database": "northwind"
    }
    
    async function beforeRender(req, res) {
        await sql.connect(config)
        const sqlReq = new sql.Request();
        const recordset = await sqlReq.query(
            `select count(*) as Count, ShipCountry  
             from Orders group by           
             ShipCountry`
        )
        Object.assign(req.data, { countries: recordset });         
    }
    


  • Hi, thank you for fast response...
    I tried it but I still can't show the data from database table...

    do you have any suggestion ?
    thank you so much


  • administrators

    do you see some different error error after changing the code or do you see the same?

    can you share the new code that you have now (just to double check that you don't have some mistake)?



  • Hi, I'm new to jsreports and I have the same problem. It seems to be recovering from the database but it does not show it. In my database I have 4 data and this matches the foreach that shows 4 times the ID but does not show its values. I am applying the code of jan_blaha.


Log in to reply
 

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