Requested Unknown Parameter, but works if data in var

Requested Unknown Parameter, but works if data in var

TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

I am getting this error DataTables warning: table id=OpenQuotes - Requested unknown parameter 'QuoteHed_QuoteNum' for row 0, column 0.
It is response.body from Node Request.
If I paste the response that was logged in the consol into a variable and use that variable the table loads fine, but if I try to use the response with the same data I get the error above. I can't quit figure out why it would be any different.

{
"odata.metadata":"https://site/internal/api/v1/BaqSvc/Portal-OpenQuotes/$metadata#Epicor.DynamicQuery.QueryResults","value":[
{
"QuoteHed_QuoteNum":28040,"QuoteDtl_QuoteLine":1,"QuoteHed_EntryDate":"2020-01-03T00:00:00","QuoteDtl_custPNquote_c":"","QuoteDtl_OrderQty":"181169.00000000","QuoteDtl_ExpUnitPrice":"0.00000","UDCodes_CodeDesc":".75SQ","QuoteDtl_Gage_c":"16","QuoteDtl_length_c":"143.5000","QuoteDtl_pieces_c":15150,"QuoteDtl_Type_c":"HR","QuoteDtl_grade_c":"","QuoteDtl_Ends_c":"","QuoteDtl_piecePrice_c":"4.41860","RowIdent":"b12d37b1-484b-4713-8cf7-58a5d781d6a0"
}
]
}

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Well, its hard to say without seeing your Datatables init code and what you are doing when using the data as a Javascript variable. My guess is you need to use ajax.dataSrc with the value of value.

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0
    edited June 2020

    **This is in the route **

     request(options, function (error, response) { 
         if (error) throw new Error(error);
           var test = response.body;     
    
        
         res.render("quotes", {data: test.value});
         console.log(test)
    

    This is in the ejs file.

     <script type='text/javascript'>
        
            var resData = <%- JSON.stringify(data)%>
    
            $(document).ready(function(){
                $('#OpenQuotes').DataTable( {
                    "data": resData,
                    "columns": [
                    { "data": "QuoteHed_QuoteNum", },
                    { "data": "QuoteDtl_QuoteLine" },
                    { "data": "QuoteHed_EntryDate" },
                    { "data": "QuoteDtl_custPNquote_c" },
                    { "data": "QuoteDtl_OrderQty",},
                    { "data": "QuoteDtl_ExpUnitPrice", },
                    { "data": "UDCodes_CodeDesc", },
                    { "data": "QuoteDtl_Gage_c" },
                    { "data": "QuoteDtl_length_c" },
                    { "data": "QuoteDtl_pieces_c" },
                    { "data": "QuoteDtl_Type_c" },
                    { "data": "QuoteDtl_grade_c" },
                    { "data": "QuoteDtl_Ends_c" },
                    { "data": "QuoteDtl_piecePrice_c" }          
                ]
                });
            })
        </script>
    

    Edited by Kevin:  Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Guessing that res.render("quotes", {data: test.value}); responds with JSON data. If so then var resData = <%- JSON.stringify(data)%> is JSON encapsulating the data again. Maybe you need to use JSON.parse() instead. And you may need to use "data": resData.value,.

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

    the JSON.parse() threw errors. Its Odd because the log of resData looks as it should I think.

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited June 2020

    the JSON.parse() threw errors

    Are you referring to the error in the screenshot or some other error? The error in the screenshot is a Datatables error not a JSON.parse() error.

    Hard to tell from the screenshot but does your data still look like this structure?

    {
        "odata.metadata": "https://site/internal/api/v1/BaqSvc/Portal-OpenQuotes/$metadata#Epicor.DynamicQuery.QueryResults",
        "value": [{
            "QuoteHed_QuoteNum": 28040,
            "QuoteDtl_QuoteLine": 1,
            "QuoteHed_EntryDate": "2020-01-03T00:00:00",
            "QuoteDtl_custPNquote_c": "",
            "QuoteDtl_OrderQty": "181169.00000000",
            "QuoteDtl_ExpUnitPrice": "0.00000",
            "UDCodes_CodeDesc": ".75SQ",
            "QuoteDtl_Gage_c": "16",
            "QuoteDtl_length_c": "143.5000",
            "QuoteDtl_pieces_c": 15150,
            "QuoteDtl_Type_c": "HR",
            "QuoteDtl_grade_c": "",
            "QuoteDtl_Ends_c": "",
            "QuoteDtl_piecePrice_c": "4.41860",
            "RowIdent": "b12d37b1-484b-4713-8cf7-58a5d781d6a0"
        }]
    }
    

    If so did you use "data": resData.value, in the Datatables init code?

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0
    edited June 2020

    var resData = <%- JSON.parse(data)%> gives an error of Uncaught SyntaxError: Unexpected identifier

    Yes the structure above looks like my structure.(However each value is not on a different line.
    Without Json.parse using "data" : resData.value Gives No Data is Available in the table. I must be missing something totally simple..

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    Answer ✓

    I'm not familiar with using <%...%>. Seems like a templating thing.

    What does console.log( typeof resData ); output?

    What does console.log( resData.value ); output?

    However each value is not on a different line.

    Yes, it looks like its the key for an array of objects which is what Datatables is looking for.

    Kevin

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

    Data type is string. So it should be looking for Ojbect not string?

  • TB_MikeTB_Mike Posts: 15Questions: 4Answers: 0

    That is the problem. Removing json.stringify completly so that it is an objec then using resData.value for the table data made it work. Thanks!

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923

    Yep. JSON.parse() will parse the JSON string into an object. Not sure how to use it with your template though.

    Kevin

This discussion has been closed.