How to set field value after create a content type.
I have a content type TEST and set this actions:
- Reacts on event: Entity insert
- Add Action: Set field value->Target Entity Type: Content->Target Bundle: TEST
- Select Field: Field_test-> Set Value: "Test"
Then I create content of type TEST, but the field is not fill with value set in the rules.
Where I'm wrong?
Thanks.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | business_rules-3019450-Set-field-value-10.patch | 834 bytes | yseki |
Comments
Comment #2
c.e.a commentedIt seems the action "Set field value" action is not working for the latest beta version...
Do the below for a good alternative workaround...
Reacts on the event:
Type: After entity update
Target Entity Type: Content
Target Bundle: Article
Create a variable:
Type: Empty Entity variable
Target Entity Type: Content
Target Bundle: Article
Action#1:
Type: Fetch entity variable by id
Target Entity Type: Content
Target Bundle: Article
Entity id field: ID [Nid]
Variable: Choose the created Empty Entity variable.
Value: [node:nid]
Action#2:
Type: Set values to entity variable.
Variable: Choose the created Empty Entity variable.
Action#3:
Type: Save entity variable.
Variable: Choose the created Empty Entity variable.
Check my video:
https://www.youtube.com/watch?v=YTzHezupA9Y
Comment #3
c.e.a commentedComment #4
publishing future commentedThank you for the workaround. But why is this issue closed and set to "works as designed"?
If the action "Set field value" action is not working, this should nevertheless be fixed. I still encounter the same problem with the latest dev. Therefore set back to "Needs work".
Comment #5
c.e.a commentedI found out the "Set field value" action is working only in very specific cases but generally it is not...
This issue is added now to the important bug report list of issues #3041221: List of all 'Bug reports' that need immediate support Assigned to: yseki
Thank you for pointing out on this issue.
Comment #6
c.e.a commentedComment #7
lexsoft00 commentedHi,
If you are using tokens it might be that it will only work if few conditions are met and the token value is available. It will also not work if you are trying to modify an entity that does not exist yet. Example on entity insert will not work since the entity has not been saved, it will work if you are modifying another bundle then the same one that rule event uses.
If you would like the action to work with different bundles you should try the patch posted here https://www.drupal.org/project/business_rules/issues/3033723 even if it's not ideal and only a sandbox patch.
I will try to make a proper patch to add this functionality as an extension to the existing action type.
Hope this helps
Comment #8
c.e.a commented@lexsoft the 'set field value' action is not working even for the simplest cases.
Example:
RULE
Entity is viewed
ACTION
Set field value.
field_user_family_nameLogged in as uid 1, after I view my profile, then I go to
/user/1/editpage, I expect to see thefield_user_family_namevalue = My new family name but the value of the field is still empty or equal to previous value.Thank you,
Comment #9
colanThere's no code here so updating status. As usual, patches welcome.
Comment #10
c.e.a commentedComment #11
yseki commentedIt's is a misuse of the action.
This action is applicable only during the saving event, that corresponds to entity_presave hook or "Before saving entity" rule.
Here is a patch that filters the action to not be available for the wrong rules.
Comment #13
colanFixing status.
Comment #14
djween commented1. Using event: Before Saving Entity:
--I can add action: Set field value which is good. However,
--on same rule if I add a condition and need to set a field based on a condition, I cannot add action: Set field value within the condition on that same rule. To clarify - I can add Set field value if condition is to compare data values and set to bundle but I can't add Set field value if comparing variables. Is this by design?
2.
Additionally: workaround in comment #2, for me I found that tokens are pulling in values for most recently created node no matter which node I subsequently update. As a result, node is being updated with incorrect data.Scratch this second comment. I have a very specific use case where I am not able to do this and have a separate issue opened for it: https://www.drupal.org/project/business_rules/issues/3136784