Thanks @shanebp for the guidance. I read some about add_action and manage to get the function to work as desired.
For people interested, this is what I did. I created a custom function that follows:
add_action( 'bp_ready', 'custom_function' );
// The ID of the field, or the $name of the field.
function custom_function($user_id){
$field = 'fieldname';
// How should array data be returned? 'comma' if you want a
// comma-separated string; 'array' if you want an array.
$multi_format = 'comma';
// NOTICE! Understand what this does before running.
$result = xprofile_get_field_data($field, $user_id, $multi_format);
return $result;
}
The main function that I wanted to get the profile data was then called.