I am trying to get my database to update with the date and time of a submission onClick of a 'Submit' button.
Currently tried (From www.wix.com/code/reference/wix-data.html#update):
----
let toUpdate = {
"expiration": $w.getTime()
};
export function button26_click(event, $w) {
wixData.update('#dataset1', toUpdate)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
}
----
I have also tried:
----
let toUpdate = $w.getTime();
export function button26_click(event, $w) {
$w('#dataset1').setFieldValue('expiration', toUpdate);
}
----
This does not throw any errors in the console but it does not update the collection 'Expiration' column either.
Basically what I have is a set of redemption codes that can be redeemed by retailers and on the redemption code dynamic item page it shows the expiration date of the codes. I want to be able to update the expiration to the date/time the code was redeemed (submit button clicked) to make it easier to stand out if the redemption codes dynamic item page is pulled up again and has already been redeemed.
Hay Curtis,
$w does not have a function called getTime(). Instead, use new Date() - which is always pointing by default at now.
e.g.
export async function button26_click(event, $w) { let item = await wixData.get(<collection>, <item id>); item.expiration = new Date(); await wixData.update(<collection>, item) }
or
export function button26_click(event, $w) { $w('#dataset1').setFieldValue('expiration', new Date()); }
I m having a similar issue, I followed your code but theres an error. Can you fix this,
import wixData from 'wix-data'; $w.onReady(function () { //TODO: write your page related code here... });
export async function button45_click(event, $w) { let item = await wixData.get(<NewCarInquires>, <date>); item.expiration = new Date(); await wixData.update(NewCarInquires, date) }
My data base name is NewCarInquires and field name is date.
I have a similar requirement. only slightly different. I need to change the color of my container box from red to green on single click and green to red on double click. Once the color is changed it should be updated automatically so that the other user login into my website can see the same change done.
Please guide me how to do it.
Beautiful!
Thank you for the quick response and it worked perfectly. It even updated on the current page as soon as the submit button was pressed and that is an added bonus as it verifies to the retailer that the code has been updated on top of the confirmation dialogue.