Every time I try to 'set a data value' on a profile type's field, it will not set a value if the field is already empty. It will only set the value if the field has (or once had) existing content within it. So far I have tried to do this with the following fields 'Link', 'Text' and 'Date' and all appear to be having the same problem.
I'm not sure if it's of any consequence but this is in relation to setting data values in a Profile2 content type.
When looking in 'Recent Log Messages' there always appears to be a report of the type 'The variable or parameter entity is empty'
Comments
Comment #1
spessex commentedPlease note I have also noticed that 'Set a data value' will only work and write data to a field if that field has or 'used to have' data contained within it. If the field is brand new/fresh and has never had any data the 'Set a data value' will not write to it.
Comment #2
spessex commentedTo reproduce try the following:
1. Install Profile2.
2. Go to 'Profile Types'
3. 'Add a profile type'.
4. 'Manage fields'
5. 'Add a new field' - a 'text' field for instance. Do the usual saves etc.
6. Create three different user profiles.
7. Add data to the 'text field' of one of them, save and leave it there. Do the same for the second user but this time go back into the profile and delete the data from the the text field so nothing is there again. On the third user do not do anything to profile i.e do not edit or save so it's never had any data contained within it.
Now to add the rule - there's various ways to test and they all have the same problem with not being able to save data but for now just try method below or any method of your choosing
8. 'Add a new rule'
9. Event ' User has logged in'
10. Condition 'Entity has field', Parameter:Entity [account:profile-name-of-profile], Field: [name of field]
11. Actions. 'Show a message on the site' (this is to show whether the rule is working or not to this point). Choose what ever message you want.
12. Add the final Action (which is the main problem with this issue). 'Set a data value'. Parameter: Data:[account:profile-name-of-profile] Value: [any text].
Now to test the rule
13. Login for one by one for all the three users. You will notice that the data will be set for the first two users but not the third (where data has never been set). But please notice user 2's data is set even though there is no data which had been deleted. I believe it has been set because Drupal is aware that it 'used' to have data present.
Comment #3
spessex commentedRule exported for help:
{ "rules_test" : {
"LABEL" : "Test",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_login" ],
"IF" : [
{ "entity_has_field" : {
"entity" : [ "account:profile-live-surveys" ],
"field" : "field_test_text"
}
}
],
"DO" : [
{ "drupal_message" : { "message" : "The value of Link in Active Surveys is empty and rules will now add a link." } },
{ "data_set" : {
"data" : [ "account:profile-live-surveys:field-test-text" ],
"value" : "dfs do cheap couches"
}
}
]
}
}
Comment #3.0
spessex commentedjust changed grammar
Comment #4
jackdaniel9 commentedSame problem,
It's not possible to set a data value for User Profile ?
Commerce Kickstart :
When the user Completing the checkout process, we want Set a Data Value for the User Current Profile....but not work.
Comment #5
zrodimel commentedSame problem here. Any ideas?
Comment #6
msamavi commentedSame problem here.
Comment #6.0
msamavi commentedAdd (or once had) in regards to the data
Comment #7
loparr commentedI can confirm problem still exists. Any workarounds?
Comment #8
taburk commentedFinally figured this out - the profiles aren't created as entities until one of the fields actually has content, so you're trying to set the data value for a field in an entity that doesn't exist. The solution is just to add a "create new entity" action for the profile you're trying to edit and 'set data value' should work as expected.
Comment #9
wOOge commentedDid a test — tried to set data value for a text field in
A) Profile2
B) and the same text field in a User->(core) Profile
Setting data value does not work on fields in Profile2, but they DO work in core user profile fields.
Comment #10
spanners commented#8 worked! Thanks very much taburk. Saviour!
Comment #11
tr commentedClosed #2635494: Updating profile2 fields with rules as a duplicate.