Hi all,

I want to change the value of a profile2 field during a rules action with PHP. The name of the field is given by a variable called "fieldname", the field is an entity reference to an user:

$user_uid = $booking-user->uid;
$profile_name = 'profile_user';
$profile_entity = profile2_load_by_user($user_uid, $profile_name);
$field_change = $profile_entity->$fieldname;
$booking['und'][0]['target_id'] = 122;
profile2_save($profile_entity);

The profile is loaded but not saved... maybe profile2_save does not work within a rules action?

Best,
Tobias

Comments

VasilyKraev’s picture

Same problem. After creating new user, I got system message, user with change e-mail, but no changes in profile.
I use following rule:

{ "rules_on_user_save" : {
    "LABEL" : "on_user_save",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "user_insert" ],
    "DO" : [
      { "drupal_message" : { "message" : "Rule - on_user_save" } },
      { "data_set" : { "data" : [ "account:mail" ], "value" : "test@example.com" } },
      { "data_set" : {
          "data" : [ "account:profile-main:field-full-name:family" ],
          "value" : "family"
        }
      },
      { "data_set" : {
          "data" : [ "account:profile-main:field-full-name:given" ],
          "value" : "first"
        }
      }
    ]
  }
}
HenrikBak’s picture

I have got the same issue with profile2_save(). I'm using it within a custom rule and It simply doesn't save the profile.

VasilyKraev’s picture