Requested Unknown Parameter, but works if data in var
Requested Unknown Parameter, but works if data in var

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
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 ofvalue
.Kevin
**This is in the route **
This is in the ejs file.
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Guessing that
res.render("quotes", {data: test.value});
responds with JSON data. If so thenvar resData = <%- JSON.stringify(data)%>
is JSON encapsulating the data again. Maybe you need to useJSON.parse()
instead. And you may need to use"data": resData.value,
.Kevin
the JSON.parse() threw errors. Its Odd because the log of resData looks as it should I think.

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?
If so did you use
"data": resData.value,
in the Datatables init code?Kevin
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..
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?Yes, it looks like its the key for an array of objects which is what Datatables is looking for.
Kevin
Data type is string. So it should be looking for Ojbect not string?
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!
Yep. JSON.parse() will parse the JSON string into an object. Not sure how to use it with your template though.
Kevin