When is Mention.AfterDelete called in an Automation Rule?

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]
Parents
  • Former Member
    0 Former Member

    Mention.AfterDelete is called when content (like your comment) is updated and the mention has been removed from the text. So in your example, the event should be fired. Are there any exceptions in the log?

  • Nothing in the logs, no Disappointed I've attached the exported rule if that's of any help?

    <automation name="e14 - User @mentions someone" version="11.1.8.16788" description="" id="9b28f477a12b48edb52b711f643cbf09" executeAsServiceUser="true" isSingleton="false" hostId="20621367a4734f92abef8dc33fa32a5b" trigger="Event" lastModified="2021-09-08 14:33:58Z" provider="00e14000-0e14-0e14-0e14-100000000e14">
    	<events>
    		<event key="mention.aftercreate" />
    		<event key="mention.afterdelete" />
    	</events>
    	<executionScript language="JavaScript"><![CDATA[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);
    }]]></executionScript>
    </automation>

    BTW, we're on Verint 11.1.8

  • Former Member
    0 Former Member in reply to Matt

    I tested this automation on a local 11.1.8 instance and it worked, removing the points when i edited the comment to remove the mention. 

    Does the code in the automation get reached? You can test this by adding event logging in the AfterDelete block:

    core_v2_eventLog.Write("after delete " + contentId + " " + userId, { Category: "Test", EventId: 33, EventType: "Information" });

    While this isn't what you asked about, I am logging a bug to look at how we handle mention removal when content is deleted. A workaround would be to listen to the Content.AfterDelete event and revoke points based on that.

    TE-17086

  • Hmm, strange it worked for you. The eventLog.Write doesn't get called (I uncommented my logging line in the above code sample). Here's a video of the issue too Slight smile

    https://www.youtube.com/watch?v=M1t7Bg4WjH8

    I even removed all the code & just left a single eventLog.Write in there & it doesn't get called on removing the mention from an existing comment.

Reply Children