Multiple Profile Custom Fields

I have been using:

{assign var="value" value=$user_data.fields[41]}

to work with custom field user data.

I have now activated multiple user profiles and the user_data.field is not showing the correct values for the different profiles when a customer has multiple profiles.

Any suggestion how to find the same field for different user profiles.

Suggest you develop a function that will work by name and return a field_id. I.e. like this example (modify to suit):

function my_profile_field_id($name) {
  return db_get_field("SELECT field_id FROM ?:profile_fields WHERE field_name LIKE ?s", $name);


You could then use template code like:

{assign var="field_id" value="b_firstname"|my_profile_field_id}
{assign var="value" $user_data.fields.$field_id}