Get user reference field

Hi!

In the database of members/users I have a extra field that comes from a referenced field to another field. Basically I associate Users with the Database of Companies. At the same time every company can be associated with a list of users (multi-referenced) that work in that company.

The thing is that now a need to get the associated company ID of the user with code. But I haven’t found a function that gets me this info. Is not in the “extended fields” or “custom fields” info.

Anyone know how to get this info with code??

Did you use a single reference field “company” in the Users collection ? Or a muliti-reference field (where each user can be linked to many companies and each company can be linked to many users)?

I didn’t know that you coud query the Users collection directly. Thanks for the advice! It worked.

I use (for others to use):

export async function getUserCompany ( id ) { //id = userID

  **try**  { 
    **const**  queryResult  =  **await**    wixData . queryReferenced ( "Members/PrivateMembersData" , id ,  "Companies" ) 
  
    **let**  userCompany ; 
    **if**  ( queryResult . items  &&  queryResult . items . length  >  0 ) { 
        userCompany  =  queryResult . items [ 0 ]; 
    } 
    **return**  userCompany ; 
}  **catch**  ( err ) { 
    console . error ( 'Error : ' ,  err . messsage ); 
} 

}

if you want it to be run by non-Admin member, you should add {suppressAuth: true} as a 4th argument in the queryReferenced method call.

Ok! Thanks! :+1: