Webpage: cosworthvega.com/reconcile-registry-histories
Dataset1: CVOA-Registry-History containing dash_no, entry_date, and content.
Dataset2: CVOA-Registry containing dash, vin, email of the owner, other info not needed here
There may be from to to many history records for a given dash number. The purpose is to show history records that have been entered for a given dash but not “parent” entry exists.
Code has been provided by Steve in another forum post to get the unique history records. However, their is an error in displaying the entry date on the repeater, AND the added code to retrieve the car’s vin and email address for the car owner is not working but giving errors.
Here is a screen shot of the webpage definition. If and email address is not found then the page field text "*** Not In CVOA Registory **** is not replaced.
------- CODE --------
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixData from ‘wix-data’;
let DashNo;
let VIN;
let EntryDate;
let RegisteredTo;
$w.onReady(() => {
// We return this which will delay page rendering until the data is ready
return wixData.query(“CV-History-Registry”)
.ascending(‘dash_no’) // Sort: by car’s unique dash number
.descending(“date”) // Sort: Date column is populated by a date field from the data collection
.find()
.then((result) => {
let filteredRegistry = ; // Initialize the results list we need
let uniqueColumnValue = “”; // Used to filter out the secondary dash_no records
// Loop through the result list and remove unwanted records
for ( let i = 0 ; i < result.items.length ; i++) {
let itemUnderTest = result.items[i]; // Check to see if we have see the dash_no before
if (uniqueColumnValue === itemUnderTest.dash_no) {
// We have seen a record with this dash_no before so skip this one
continue ;
}
// If we get here we have a unique (possibly the first of a list) item record
filteredRegistry.push(itemUnderTest); // Remember the dash_no
uniqueColumnValue = itemUnderTest.dash_no;
}
// The registry is now filtered
// Give the filtered list to the repeater to work with
$w(‘#repeater1’).data = filteredRegistry;
// Now Update the repeater view
$w(‘#repeater1’).forEachItem(($item, itemData, index) => {
// Get the VIN# and Owner Email from the CVOA-Registry dataset…
DashNo = itemData.dash_no;
console.log("Getting VIN and Owner for Dash: " + DashNo)
wixData.query("CVOA-Registry")
.limit(1)
.eq("dash", DashNo)
.find()
.then( (results) => {
let firstItem = results.items[0];
VIN = firstItem.vin;
RegisteredTo = firstItem.email;
} )
. catch ( (err) => {
let errorMsg = err;
console.log('ERROR: ' + errorMsg)
} );
// Load the repeater element values
$item(‘#dash’).text = itemData.dash_no;
$item(‘#vin’).text = VIN;
$item(‘#owner’).text = RegisteredTo;
$item(‘#date’).text = itemData.entry_date; // GETTING ERROR:
});
});
});
----- END CODE ----
- Date Display Error:
“Wix Code SDK Error: The text parameter that is passed to the text method cannot be value Wed Dec 3 2014 00:00:00 0500-GMT (Eastern Standard Time), It must be of type string.”
In my original code that was not filtering out the duplicates I had the following code snippet that did display the date as I wanted, but I could not figure out where to place this code in the rewrite…
let repeatedElement = $w(" #date ");
let D_String = new Date(itemData.entry_date)
let D_Locale = D_String.toLocaleDateString(“en-US”)
repeatedElement.text = D_Locale
- The wix query within the for loop Errors:
“Wix Code SDK Error: The text parameter of ‘vin’ that is passed to the text method cannot be null or undefined”.
“Wix Code SDK Error: The text parameter of ‘owner’ that is passed to the text method cannot be null or undefined”.
- Also, there are approximately 3500 unique history records to be displayed. With my dataset definition set to 100, will the pagination widget at the bottom of the page still work? Right now it is not, possibly because of these errors?