2

I'm trying to grab the contents of a field in my node of custom Content Type 'Messages'. The field is called 'targetuser'. I successfully grab the content of this field, and place it inside a field on my User profile called 'last_user_messaged' with the rule 'set a data value'. Hooray...

I then fetch the entity type User (see second action), and the field/property last_user_messaged (site:current-user:field-last-user-messaged), which in theory, should now return the data I'd set there with my first action.

That said, when I try and set my third action 'Send a push notification to a user account' with the data selector [last-messaged:1], upon execution, my logs tell me that it's empty. Technically, shouldn't last-messaged:0 return the first value inside field last_user_messaged? And last-messaged:1 return the second value? Or am I reading this wrong?

In short: I want my push notification to send to the integer (a uid) that is placed in last_user_messaged field.

I hope this makes sense.

enter image description here

1 Answer 1

1

Have a look at issue # 430274, which somehow explains that "after saving something" actually happens ... "before saving something" (which is not a bug, simply how the Rules module works ...). From the limited details provided in the question, it could well be that this also explains what causes your issue.

A possible compromise to avoid these kind of issues, is to transform relevant parts of what you're trying to do in your Rules Action(s) in a Rules Component, so that your Rule "schedules the execution" (using the Rules Scheduler submodule) of that Rules Component. For example after only a few seconds or minutes later on (if your cron job runs frequent enough, otherwise it'll be next time cron runs). This compromise will ensure that, at the time the Rules Component is executed, the "Save of the entity" for sure completed, and updates will have been applied as expected.

PS: as an alternative, add an extra "save entity", after your first Rules Action (possibly that might be sufficent also).

2
  • I tried placing a 'save entity' for entity-fetched:0 after my second rule, but got a redline error - I assume this is because the entity isn't called on until the second rule, so I tried placing it after the 2nd action. Still no dice - I get the following in error log: 'The action Save entity () was marked dirty, but passes the integrity check now and is active again.'
    – Brittany
    Commented Feb 22, 2018 at 22:02
  • 1
    Follow up: That said, you my friend, were right. It wasn't saving at the correct time. I decided to save the value in the User field a different way (via my app front end) before executing the push notification rule - worked like a charm. THANK YOU.
    – Brittany
    Commented Feb 22, 2018 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.