Make a rule fire only once?

Events happening in the community are now at Drupal community events on www.drupal.org.
kscott22's picture

I've got a rule that displays a message when a user earns more than 50 points. I'd like this message to display only once, when the user first gets above 50 points, and then not again.

Is there any way to set this up with Rules?

Thanks, in advance.

Comments

Use Flags

McGo's picture

Hey kscott22,

i think using a flag "user is above 50 points" could help without any programming. Just set the flag on the first time and add it as condition.

Cheers,
McGo

Thanks!

kscott22's picture

Thanks, McGo. I think you're talking about the Flag Module. It always helps when I don't need a new module. My site is live, and I have to go through the client's IT staff to get any new modules, etc., installed. It usually takes about a month, unfortunately.

Use Role in Rules

shushu's picture

Hi kscott22,
I wanted to show a user a notification only when he do something for the first time.
The solution I got somewhere around here is setting and unsetting specific role to the user.
Let's say you have something that gives the user a specific role ("above 50"), then after showing him the message according to it, just remove the role from him.

I think this is similar to McGo's answer, except that I am not certain what is the flag he reffers to.

Let me know if you need any additional help.
Regards,
Shushu

Thanks, shushu!

kscott22's picture

Thanks, shushu! I think I'm going to try something like that.

I'm going to create two rules. The first one states that when the user gets >= 50 points, they'll be assigned a role. Then, the second rule displays the message display ONLY when they get that new role.

Thanks so much for the quick replies -- you've made a rough week a lot better!!!

Good luck, What you described

shushu's picture

Good luck,
What you described is exactly what I meant.

More help, please

kscott22's picture

Sorry to bug you some more, but I'm still struggling. Here's what I've done:

RULE 1: If user gets points and their total points >= 50, they're assigned a temporary role.
RULE 2: If user has temporary role, they see a message, are redirected to a page, and the temporary rule is then removed.

The problem is that every time a user gets more points, the rules trigger again because their total points are still >= 50.

In the end, I'm back where I started -- I can't get the rule to fire just once. What am I doing wrong? Is there a way to trigger a rule only when the user's role changes? (I tried "user account details changed" but that doesn't work.)

Thanks again!

I've got it!

kscott22's picture

Okay, for anyone who may stumble across this discussion in the future, here's what worked (and it turned out to be a lot easier than I was making it out to be):

I made a single rule, with these parameters:

On event user earns points
IF
- user points >= 50
- AND user role is NOT temporary

DO
- show configurable message
- add role temporary

By adding the role "temporary" at the end of the rule and stating that the rule won't trigger for a "temporary" role, it ensures the rule will only fire once.

Flags

McGo's picture

If you don't know the flag module yet, you probably should have a look at it: http://drupal.org/project/flag

You can flag content and user (and anything else if you dig into programming) programmatically or in the frontend. It is really well integrated into rules and therefore is great to add a simple on/off state to something.

I will take a look. Using

shushu's picture

I will take a look. Using roles makes a mess with permissions.
While sometimes what I exactly need is to differ between users in different stages (hence permissions is very useful), sometimes all I need is to "flag" a user until I do something (like flag him until he login, then show him a message, and unflag him...).

Thanks,
Shushu

Great thread!!

drupalfan81's picture

Hey guys,

This is a great thread and I am looking for a similar/same solution. Basically I would like to have a rule fire only once but I don't want to have to deal with multiple roles, it's too messy. There has to be an easier way. Have you guys found out a different way. Here is what I want to do, now this can be applied to pretty much anything where someone wants a rule to fire only once.

On my site, I have 3 flags called, trip planner, favorites, and visited. I want to keep the interface clean, so I don't bother to explain what they are on the page. So what I would like to do is have a rule that sends the user an email (which is an explanation of the feature and what they can do) when they click the flag for the first time. But once that email gets fired off to them, I don't want them to receive the email ever again.

Consider them trained after they click it the first time and they receive the email.

This goes for other things on the site too. For example, I would love to set a rule when someone posts their first comment on my site, they receive an email that says, thanks for posting the comment, by the way, you just earned 5 points posting that comment, let me explain some other ways you can get points.

It's almost like I want to have a few switches that are on or off to indicate if this user is trained on that subject. Once they hit a button on my site, they get the email (training) and then the switch is permanently turned off.

Anyone know how I can accomplish this with Rules? I feel like its there somewhere, I just don't know where.

User fields

riverrat's picture

When I have problems similar to this I add fields to the user entity and set them when the rule fires and use them later in a rule to determine if another rule should fire.
For Example in your case

Create field user:trained boolean
Create rule

  • Event On clicking on the flag
    Actions Check if user: trained is set do nothing
    if user:trained is not set send email and set user:trained

Hope this helps

Brilliant! This is exactly

drupalfan81's picture

Brilliant! This is exactly what I am looking for. Thanks so much Riverrat. One follow up question though...how does one do this: add fields to the user entity?

Like create a new profile field for the user profile or is this something else?

Josh

More info

riverrat's picture

To create the user field
Config/People/Account Settings/Manage Fields

Add new field - Field type boolean

Change field setting in "Manage Display" for your new field to hidden

Save

Now in config/Workflow/Rules/components

Create a new condition

Entity has field for user entity

Data value (for field just created) is empty - using data selectors to give you the field name needed

Create new Actions

Send Mail

Set data value to true for the field that you have created

Thanks riverrat! I should

drupalfan81's picture

Thanks riverrat! I should have mentioned I'm on D6. It seems based on your explanation I think its for D7 right?

Do you happen to know if this is possible with D6? I can't seem to gain access to the user profile custom fields from rules for some reason. Maybe this is not possible?

D7

riverrat's picture

I am afraid it is along time since I used D6 so can not give reliable help on this

Thanks for posting riverrat.

drupalfan81's picture

Thanks for posting riverrat. I guess another pro point in the bucket to upgrade to D7. I just have so many modules that I use on this site. I need to go through the list and see if D7 versions are available now. Maybe time to finally upgrade.

If anyone comes across this thread and knows how to do this on D6, please comment. Thanks!!

User Flag

tripper54's picture

Could you just create another user flag - "email instructions sent" ? Then you could set that when you send the email, and check that it is not set before sending the email.

Tripper!! Brilliant! Wow, I

drupalfan81's picture

Tripper!! Brilliant! Wow, I just need more sleep. It was right in front of me. Yes, you are 100% right and that worked!

Here is what I did:

Created a user flag called User Trained. Made it only available to the administrator role, unchecked box to show on user profile page. I figured this made the most sense as it's going to be simply a system flag

added a condition on my rule to check "user is flagged"

Selected the flag "User trained" and select the negate checkbox

then in the DO section of the rule, I selected "flag a user" then selected the "user trained" flag. There was a checkbox to apply permissions, I just left that unchecked and it appears to be fine.

Bingo...it works.

Basically the first time the user flags content with the flag that I set to check the rule "a node has been flagged, under {flag name}" it will send him an intro email, set the "user trained" flag, and then everytime he/she uses that flag in the future no email sent. Perfect!!

Thanks everyone!

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: