setfieldvalue

I have created a page, which, when a site member visits, is supposed to change certain values for this member.

The basic problem is that it seems not to recognize the current item, but instead creates new ones.

So instead of saving the change to the current Member item, the code creates two new items. Can someone recommend a fix?

In this example, I want to set the “status” field to “Annual Membership”.

dataset2 is the Member database. Each item is created when someone joins my site. Permissions in this database are set to:
read: site member author
create: site member
update: site member author
delete: admin

On the site page I am working on, the dataset settings are “read & write”

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;

$w.onReady( function () {

$w(“#dataset2”).onReady( () => {
$w(“#dataset2”).setFieldValue(“status”, “Annual Membership”);
$w(“#dataset2”).save();
});

});

Have a read of the API reference so that you are using the code as it should be.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue

Although, if you have setup your members page similar to this tutorial here
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area
Then you should have already been able to let members update their own profiles etc and have a membership status already shown on the profile page which lists their current membership status.

Thanks. I had previously reviewed this page and it seems my code is exactly as it says it should be. Where do you see the error?

Note also my page is static not dynamic. However I still expect wix to see the current item in the member database.

Site member pags are unique to each member, hence why they have their own unique id etc and use dynamic pages.
https://support.wix.com/en/article/introducing-dynamic-pages
https://support.wix.com/en/wix-data/dynamic-pages

Hence why member profile pages are dynamic like in this Wix tutorial here.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

$w.onReady( () => {
$w("#myDataset").onReady( () => {
$w("#myDataset").setFieldValue("title", "New Title");
} );
} );

Yes but why doesn’t my code work? I think your point is off-topic. Even if it is a static page wix should call up the single item that the member has permission to see and recognize that as the current item. I have used this same strategy for static pages throughout my site (e.g to display tables or text fields on static pages linked to the member dataset). So my original question remains - why doesn’t wix recognize the current item and why does it instead add new items when i use setfieldvalue?

1 Like

something similar happened to my code (just stopped working) when Wix came out with this great new database update.

That makes sense. I had thought this code previously worked.