Can't get the User Custom Fields

Hello, I am trying to get the data from the custom fields from a member in webflow but I just can get it. Here is the custom code that I am using for trying to see the data in the browser console:

EDITED: Sorry I didn’t read that you have to declare the custom fields IN the Account Page, in order to been called by the Attribute. Once you called this custom fileds in the account page, they are getting by the code.

------------------------------- CODE ---------------------------------------

<script type="module">
import { WfuUserInfo, WfuUser } from 'https://cdn.jsdelivr.net/gh/sygnaltech/webflow-util@4.7/src/modules/webflow-membership.js'; 
import { WfuDataBinder } from 'https://cdn.jsdelivr.net/gh/sygnaltech/webflow-util@4.7/src/modules/webflow-databind.min.js'; 

$(function() {
  var membership = new WfuUserInfo({
    userInfoUpdatedCallback: myCallback
  }).init(); 
});  

async function myCallback(user) {
  // Automatic data-binding using attributes
var dataBinder = new WfuDataBinder({
    user: user
  }).bind();

if(user.user_data_loaded.email) {
    console.log(user.email); // Show the current user's email
}
if(user.user_data_loaded.custom_fields) {
     var collaborator = user.data["collaborator"];
     var projectid = user.data["projectid"];
     console.log(collaborator); 
     console.log(projectid);
    return;
  }
}

</script>
2 Likes

Glad you got it Miguel!

Correct- Webflow does not directly make the user data available to script for your use, so we have to pull it from the account screen using a bit of creative timing magic.

Note that these fields do not need to be visible, but they must exist in order for the script to access them. You can set display: none, or wrap them in a DIV that hides an entire group of them. This is particularly useful for eg. external system IDs.