context_v1_pointsAutomation.AwardPoints assigns points twice

Hi, I have developed a custom points automation for assigning points to a reply author when someone likes the reply (Event: ForumReplyVote.AfterCreate).

It works well if a user clicks the vote up/down button, but when the thread author makes the reply as a "verified answer," the system automatically fires a "Vote" event and assigns the points twice.

In the logs, below statement being called only once, but i see two entries in pointtransaction table in the database.

context_v1_pointsAutomation.RevokePoints(userId, context_v2_automationTrigger.Arguments.ContentId, context_v2_automationTrigger.Arguments.ContentTypeId);

logs:

25 Oct 2021 12:57 PM2 TimesIP 10.208.190.46
Assign points to content author- Ended

25 Oct 2021 12:57 PM2 TimesIP 10.208.190.46
Assign Points

25 Oct 2021 12:57 PM2 TimesIP 10.208.190.46
awardedPoints:: false

ContentFragmentRenderingError
25 Oct 2021 12:57 PM2 TimesIP 10.208.190.46
Assign points to content author -started

Any help on this will be greatly appreciated.

Thank you!!

Parents
  • Former Member
    0 Former Member

    If you are aiming for it to only be assigned once per user per thread, use context_v1_pointsAutomation.ArePointsAwarded to confirm whether points already exist for that user and thread.

    I'm not sure how that code snippet is related since that would be revoking points. I also don't know where your event log messages are firing from.

    I see a ContentFragmentRenderingError. Does looking this error up in the exceptions log provide any additional details?

  • Hi Steven, Thank you for the response. I dont see any exception in the logs.

    Below is the code snippet. It fires on - ForumReplyVote.AfterCreate event

    var userId = context_v2_automationTrigger.Arguments.UserId;
    core_v2_exceptions.Log("Assign points to content author -started");
    var forumReplyResponse = core_v2_forumReply.Get(context_v2_automationTrigger.Arguments.ReplyId);
    var awardedPoints = context_v1_pointsAutomation.ArePointsAwarded(forumReplyResponse.Author.Id, forumReplyResponse.contentId, core_v2_forumReply.ContentTypeId);
    core_v2_exceptions.Log("awardedPoints"??+ awardedPoints);
    if (!awardedPoints) {
    context_v1_pointsAutomation.AwardPoints(forumReplyResponse.Author.Id, forumReplyResponse.contentId, core_v2_forumReply.ContentTypeId);
    }
    core_v2_exceptions.Log("Assign points to content author- Ended");

    I brought this code to my Vanilla version of the community and tried. Again, I see the same issue. After the "verify answer" action, the system fires my custom achievement once, but awards point twice.

    Thanks you!

  • Former Member
    0 Former Member in reply to cdns123

    I was able to run the above code successfully and only have points assigned once. A development note - you might want to use core_v2_eventLog instead of core_v2_exceptions, it might make it easier to track since duplicate exceptions get rolled up.

    Where are you verifying where points are assigned? Can you share a screenshot?

    I'm assuming you've created a configured points rule using this automation, otherwise it wouldn't be running at all. Can you confirm you only have one configured enabled points rule using this automation?

Reply
  • Former Member
    0 Former Member in reply to cdns123

    I was able to run the above code successfully and only have points assigned once. A development note - you might want to use core_v2_eventLog instead of core_v2_exceptions, it might make it easier to track since duplicate exceptions get rolled up.

    Where are you verifying where points are assigned? Can you share a screenshot?

    I'm assuming you've created a configured points rule using this automation, otherwise it wouldn't be running at all. Can you confirm you only have one configured enabled points rule using this automation?

Children
No Data