Hello,
I want to retrieve the value of a custom field from a contact. The key to my field is “your-documents”.
I tried using the documentation available here : getMember - Velo API Reference - Wix.com
But I can’t get the value.
Here are the codes I tested
import { currentMember } from ‘wix-members’;
$w.onReady(function () {
currentMember.getMember()
.then((member) => {
const fullName = `${member.contactDetails.firstName} ${member.contactDetails.lastName}`;
const Test1 = `${member.contactDetails.customFields}`;
const Test2 = `${member.contactDetails.customFields.custom.vos-documents}`;
const Test3 = Test1["custom.vos-documents"];
console.log("fullName : ", fullName); // fullName : Nicolas Suteau (OK)
console.log("Test1 : ", JSON.stringify(Test1, null, 4)); // Test1 : "[object Object]"
console.log("Test2 : ", Test2); // Error : TypeError: Cannot read properties of undefined (reading 'vos')
console.log("Test3 : ", Test3); // Test3 : undefined
})
});
1 Like
L’équipe de Wix m’a donné la solution :
Voici comment retrouver la valeur :
const Test1 = member.contactDetails.customFields[‘custom.vos-documents’].value
1 Like
console.log(member) : to find the KEY of your custom field.
Thank you so much for publishing this @production44747, I’ve spent multiple hours trying to find how to use the custom field. The Wix Velo doc does not mention how to use it. For anyone who might be having issues, here’s how I’ve done it.
So first, I created a custom field in the member settings in the Wix admin panel. I first created the field called Preferences notifications.
I then changed its name to Courriels. The thing is, when I was trying to use the custom field in the code panel, courriels was not working. That is because the key of the field was still the first name I had given it, which was Preferences notifications.
So by using the console.log(member), I was able to find this in the developer console
So, to get the value of that custom field, I had to do it this way
import { currentMember } from 'wix-members-frontend';
$w.onReady(function () {
currentMember.getMember()
.then((member) => {
console.log(member)
const courriels = member.contactDetails.customFields['custom.preferences-notifications'].value;
})
Hope that can help anyone in the future who wants to use custom fields for members on their Wix website.
2 Likes
Like i already told you → CONSOLE = YOUR BEST FRIEND
1 Like