We're looking at a points automation to award a few points when our users @mention someone/something on the site.. limited to awarding X points per piece of content, and not for multiple mentions.
That seems to work fine..

The code behind this is;
var userId = context_v2_automationTrigger.Arguments.MentioningUserId;
// Award points per content item they use @mention in
var contentTypeId = context_v2_automationTrigger.Arguments.MentioningContentTypeId;
var contentId = context_v2_automationTrigger.Arguments.MentioningContentId;
var eventType = context_v2_automationTrigger.Event; // AfterCreate|AfterDelete
//core_v2_eventLog.Write(context_v2_automationTrigger.Entity + " -- " + context_v2_automationTrigger.Event + " Mention by " + userId + " in " + contentTypeId + " -- " + contentId, { Category: 'element14 AR', EventId: -1, EventType: 'Information' });
var awardedPoints = context_v1_pointsAutomation.ArePointsAwarded(userId, contentId, contentTypeId); // Have points been awarded already?
if (eventType=='AfterCreate' && !awardedPoints) {
context_v1_pointsAutomation.AwardPoints(userId, contentId, contentTypeId);
}
// Not sure when this ever gets called.. tried removing people and it doesn't fire AfterDelete
if (eventType=='AfterDelete' && awardedPoints) {
context_v1_pointsAutomation.RevokePoints(userId, contentId, contentTypeId);
}
It works nicely for AfterCreate, but I noticed if I subsequently edit the content (in this case a comment) & remove the @mention then I don't see the automation called with AfterDelete. I also tried deleting the comment & nothing happened there either.
So my question is, when does AfterDelete actually get called?
corrected code
[edited by: Matt at 2:34 PM (GMT 0) on Wed, Sep 8 2021]