Awarding badges multiple times with custom SQL

I have a badge that’s awarded to people who attend one of our regular events. Because it’s not straightforward to grant badges en masse, I’m using custom SQL to grant the badge. What’s not working, though, is receiving the badge multiple times. I’ve tried to make this work by having one group per event, and including the group’s creation date as the granted_at field:

SELECT
	user_id,
	created_at granted_at,
	NULL post_id
FROM
	group_users
WHERE
	group_id IN (
		SELECT g.id FROM groups g WHERE g.name IN (
			'vit-2016-s2',
			'vit-2017-s1',
			'vit-2017-s2'
		)
	) AND (
		:backfill
		OR user_id IN (:user_ids)
	)

Even though I’m a member of all three of these groups, and in Data Explorer I see three results for my user, there’s still only one instance of the badge that’s granted.

How would I go about changing this so that the badge will automatically be awarded to each user for each group they’re a member of?

Sorry to bump this, but the next round of events is coming up soon and I’d love to have this fixed ahead of time. :wink: Any ideas on how I can grant a badge multiple times without it being linked to a post? (Or should I set the post_id to the announcement post using an ever-growing case statement?)

Using a case statement and targeting posts seems to have resolved it. So it seems that badges which are not manually awarded can only be granted multiple times if they target posts. Is this something that could be made clearer on the page? Should I repost to #ux or #feature to suggest this?

1 Like