Hello. I am trying to pull data from two tables that are linked by Product Number. Then I need to group by Product Number within a date range.
For some reason, any linked field won't show up in the results.
Here is my code:
// Show first name and note, and retrieve the last name from the connected record
$(document).on('knack-scene-render.scene_144', function (event, view, data) {
// Add a button to execute the action
$("#view_1452").prepend("<button id='showproducts'>Show Products</button>");
// Add the function to the button
document.getElementById('showproducts').addEventListener('click', function () {
$.ajax({
url: "https://api.knackhq.com/v1/objects/object_80/records",
cache: false,
async: false,
type: "GET",
headers: {"X-Knack-Application-Id": "APP ID",
"X-Knack-REST-API-Key": "API CODE"
},
success: function (product)
{
$.ajax({
url: "https://api.knackhq.com/v1/objects/object_81/records",
cache: false,
async: false,
type: "GET",
headers: {"X-Knack-Application-Id": "APP ID",
"X-Knack-REST-API-Key": "API KEY"
},
success: function (lineitems)
{
document.write("<p> *** Now matching records *** </p>");
// Loop through the product and lineitems to see if a connectionID from product matches a name ID.
// If so, print the first name from product table, the surname from lineitems table, and note from product table.
for (var x = 0; x < product.records.length; x++) {
for (var y = 0; y < lineitems.records.length; y++)
{
if (product.records[x].field_896_raw[0].id == lineitems.records[y].id)
document.write("<p>" + product.records[x].field_896 + " " + lineitems.records[y].field_908 + "</p>");
} // for y
} // for x
document.write("<p> *** DONE *** </p>");
}, // success
error: function (xhr)
{
sweetAlert("An error occured! Status: " + xhr.status + " " + xhr.statusText);
}
}); // inner ajax */
}, // outer success
error: function (xhr)
{
sweetAlert("An error occured! Status: " + xhr.status + " " + xhr.statusText);
}
}); // outer ajax
});
});