Undefined Field in my database

Hi:

I set an expiration date for my customer as a warranty information display (2-year warranty). Everything was great until last weekend, the repeater in the profile page of my customer is showing undefined/NaN/NaN. I have not changed the code so I don’t know what to do. Please help. : (

Here’s the screenshot of the repeater, the “Expiration Date” should say 7/1/22 instead of undefined/NaN/NaN

There’s been an error notification since I complete the code, but it did not have any problems displaying the expiration date before. Is there any update about the code that I missed?

I also include the code as follows:
The code on the profile page:

import wixData from ‘wix-data’ ;

$w . onReady ( function () {
$w ( “#repeater1” ). onItemReady ( ( $item , itemData , index ) => {
$item ( “#expiredtime” ). text = itemData . expiredTime ;
});

$w ( “#table1” ). columns = [
{
“id” : “col1” ,
“dataPath” : “orderNo” ,
“label” : “Order Number” ,
“type” : “string”
},
//{
//“id”:“col2”,
//“dataPath”:“youProductOrderDate”,
//“label”:“Order Date”,
//“type”:“string”
//},
{
“id” : “col2” ,
“dataPath” : “expiredTime” ,
“label” : “Expiration Time” ,
“type” : “string”
}
]

$w ( “#productregistersumbit” ). onAfterSave ( ()=>{
$w ( “#dataset1” ). refresh ();
})
})

export function button5_click ( event ) {
wixData . query ( “ruqv4bl26cup3a” )
. eq ( “orderNo” , $w ( “#input5” ). value )
. or ( wixData . query ( “ruqv4bl26cup3a” ). eq ( “email” , $w ( “#input5” ). value ))

. find ()
. then ( res => {
$w ( “#table1” ). rows = res . items ;
})
// Add your code for this event here:
}

AND the code about setting the expiration date:

export function ruqv4bl26cup3a_afterQuery ( item ) {
item . expiredTime = setExpiredTime ( item . youProductOrderDate );

return item ;

function setExpiredTime ( youProductOrderDate ) {
var originalDate = new Date ( youProductOrderDate );
var date = new Date ( originalDate );

// set expiration 2 year 
date . setDate ( date . getDate () +  731 ); 

**const**  monthNames  = [ "January" ,  "February" ,  "March" ,  "April" ,  "May" ,  "June" ,  "July" ,  "August" ,  "September" ,  "October" ,  "November" ,  "December" ]; 
**const**  day  =  date . getDate (). toString (); 
**const**  longMonth  =  monthNames [ date . getMonth ()]; 
**const**  year  =  date . getFullYear (). toString (); 

**var**  expiredTime  =  longMonth  +  "/"  +  day   +  "/"  +  year ; 

**return**  expiredTime . toString (); 

}
}

English is not my native language, sorry for any mistake or possible misleading word usage in my post. :frowning:

Thank you in advance!

The expiration date displays as undefined/NaN in the Repeater since the values in the database collection are all undefined/NaN. You will need to ensure that proper values are being saved to the database.

Thank you for your prompt reply! The value of The expiration date is: 1. calculated by the data.js and displayed on the repeater; 2. manually added to the table on the profile page by writing the code:

“id” : “col2” , “dataPath” : “expiredTime” , “label” : “Expiration Time” , “type” : “string”

Do you mean that I need to write some code to save the calculated date (The expiration date) to the database?

@judytaylor1975 Yes - you need to save the calculated date in the database.

@yisrael-wix Thank you for your reply! I managed to save the calculated date by adding new code. But here’s a new problem: The warranty date only works for the order number I put in after the code is updated. The field (warranty date) of all the previous order number do not update with the warranty date. Is there anything wrong with my code?

$w ( “#productregistersumbit” ). onReady ( () => {
$w ( “#productregistersumbit” ). setFieldValue ( “Expiration” , $w ( “#expiredtime” ). text );

} );

$w . onReady ( function () {
$w ( “#repeater1” ). onItemReady ( ( $item , itemData , index ) => {
$item ( “#expiredtime” ). text = itemData . expiredTime ;
});

$w ( “#table1” ). columns = [
{
“id” : “col1” ,
“dataPath” : “orderNo” ,
“label” : “Order Number” ,
“type” : “string”
},
//{
//“id”:“col2”,
//“dataPath”:“youProductOrderDate”,
//“label”:“Order Date”,
//“type”:“string”
//},
{
“id” : “col2” ,
“dataPath” : “expiredTime” ,
“label” : “Expiration Time” ,
“type” : “string”
}
]

$w ( “#productregistersumbit” ). onAfterSave ( ()=>{
$w ( “#dataset1” ). refresh ();
})
}

I really don’t understand what you are trying to do.

Where is the code where you are saving the calculated date?

Is #productregistersumbit a dataset? If so, the a dataset onReady() should be defined in the page’s onReady() function. And, is the #expiredtime text element in the Repeater? If so, you can’t access it using $w. You need to identify which repeater item has the #expiredtime that you want using the Repeated Item Scope .

Also, setFieldValue needs a field key which always starts with a lowercase letter. You want expiration , not Expiration - like this:

$w("#productregistersumbit").setFieldValue("expiration", $w("#expiredtime").text);

What is #table1? Where are you using it?