Achievement Expiry Automation

We are interested in looking to implement an expiry period for certain Achievements.  I believe what makes the most sense is leveraging the scheduled automation type running daily.  At the moment an Award date field will be the source for the comparison and would like to revoke the achievement 2 years after this award date.  Any advice or examples on how something like this can be implemented would be greatly appreciated!

Parents
  • Hi . There are a number of ways you could approach this, but I think your initial idea is the best. 

    Essentially, it would be a matter of updating existing event-based automation achievements to also run on a schedule. Out of the box, they only handle events. However, they could be edited to also run on a configured schedule, such as daily at 2 am.

    Then you could update the implementation to branch based on how it was triggered by checking context_v2_automationTrigger.Event. The achievement is provided with a context_v1_achievementAutomation API controller that supports revoking achievements. 

    // scheduled
    if (context_v2_automationTrigger.Event == 'Executed') 
    {
        // new behavior that performs logic and ultimately calls
        // get list of users for which to revoke this achievement
        // revoke it with
        context_v1_achievementAutomation.Revoke(someUserId);
    } 
    // event based
    else 
    {
        // existing behavior...
    }

    You could combine this with use of the  core_v2_userAchievement Script API to list achievements that fall within a given window. You could also even make that window configurable by exposing a new field in the automation's Configuration to define how long that is. 

    Unfortunately I don't have a full example of this, but I do think the approach is sound.

  • Thanks Michael! I really am grateful for your insight here.  I think I have most of the logic ironed out at this point, however, I'm struggling with the API call you suggested 'core_v2_userAchievement'.  I keep getting an error and can't identify what the cause is.  I'm guessing one of the arguments I'm passing is incorrect. I'm new to working with verint and am learning a lot through this process but any guidance you or anyone else can provide would be very much appreciated.  I've included the implementation code as well as the current stack trace below.

    var unit = core_v2_widget.GetStringValue('ageUnit', '');
    if(unit === '') {
        return;
    }
    
    var achievementExpiry = core_v2_page.ParseQueryString(core_v2_widget.GetIntValue('achievementAge'));
    var currentDate = core_v2_utility.CurrentDate;
    var evalDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
    var achID = context_v1_achievementAutomation.AchievementID;
    
    if(unit === 'y')
    {
       evalDate.setFullYear(evalDate.getFullYear() - achievementExpiry);
    }
    else if (unit === 'd')
    {
        evalDate.setDate(evalDate.getDate() - achievementExpiry);
    }
    else return;
    
    var pageIndex = 0;
    var done = false;
    while(!done) {
        var users = core_v2_user.List({
           SortBy: 'JoinedDate',
           SortOrder: 'Ascending',
           PageSize: 100,
           PageIndex: pageIndex
        });
    
        for(var i = 0; i < users.Count; i++) {
            var hasAchievement = context_v1_achievementAutomation.IsAwarded(users[i].Id);
            
            if(users[i].JoinDate !== null) {
                if (hasAchievement) {
                    var userAchievementResponse = core_v2_userAchievement.Get(achID, users[i].Id);
                    var achievementCreatedDate = userAchievementResponse.CreatedDate;
                                    
                    if( achievementCreatedDate  <= evalDate) {
                        context_v1_achievementAutomation.Revoke(users[i].Id);
                    }
                }
            }
                
        }
        
        if(users.TotalCount <= 100 * (pageIndex + 1)) {
            done = true;
        }
        
        pageIndex++;
    }

    And the Stack trace:

    UnknownException: An error occurred while rendering the 'Execution' script for the automation 'Test Certification (Revoke after Specified Time)' (384f02fd4592475f92e68ff80efb5691) (An error occurred while trying to render a widget. Details of the issue were logged for review by the administrator.) ---> Telligent.Evolution.ScriptedContentFragments.Model.JavaScriptException: Line 36, Column 16: TypeError: No public methods with the specified arguments were found.
     at Get(achID, Jint.Parser.Ast.MemberExpression) @  46:36
     at call(Jint.Parser.Ast.ThisExpression) @  0:1
     ---> Jint.Runtime.JavaScriptException: No public methods with the specified arguments were found.
       at Jint.Engine.Execute(Program program, JintCallStack callStack)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.ExecuteJavascript(JavascriptExecutionContext context, String resourceName, DateTime sourceLastModifiedDateUtc, Func`1 getSource, ScriptLanguage parentLanguage)
       --- End of inner exception stack trace ---
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.ExecuteJavascript(JavascriptExecutionContext context, String resourceName, DateTime sourceLastModifiedDateUtc, Func`1 getSource, ScriptLanguage parentLanguage)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.<>c__DisplayClass47_1.<RenderScriptInternal>b__0()
       --- End of inner exception stack trace ---
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.<>c__DisplayClass47_1.<RenderScriptInternal>b__0()
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentOutputCachingService.Get(ConfiguredAutomation configuredAutomation, Func`1 getRenderedOutput)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.RenderScriptInternal(ConfiguredAutomation configuredAutomation, IPropertyTemplateOptions propertyOptions, String templateName, ScriptLanguage language, Nullable`1 cancellationToken, String friendlyTemplateName, IDictionary`2 additionalContext)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.RenderScript(ConfiguredAutomation configuredAutomation, Nullable`1 cancellationToken)
       at Telligent.Evolution.Platform.Automations.Implementations.AutomationExecutionService.<>c__DisplayClass10_0.<Execute>b__0()
       at Telligent.Evolution.Api.Services.UserService.RunAsUser(Action a, String username, Nullable`1 userId, Nullable`1 membershipId)
       at Telligent.Evolution.Platform.Automations.Implementations.AutomationExecutionService.Execute(TextWriter writer, ConfiguredAutomation configuredAutomation, AutomationTriggerContext triggerContext, Nullable`1 cancellationToken, Boolean throwExceptions)
       at Telligent.Evolution.Platform.Automations.Implementations.AutomationJob.Execute(JobData jobData)
Reply
  • Thanks Michael! I really am grateful for your insight here.  I think I have most of the logic ironed out at this point, however, I'm struggling with the API call you suggested 'core_v2_userAchievement'.  I keep getting an error and can't identify what the cause is.  I'm guessing one of the arguments I'm passing is incorrect. I'm new to working with verint and am learning a lot through this process but any guidance you or anyone else can provide would be very much appreciated.  I've included the implementation code as well as the current stack trace below.

    var unit = core_v2_widget.GetStringValue('ageUnit', '');
    if(unit === '') {
        return;
    }
    
    var achievementExpiry = core_v2_page.ParseQueryString(core_v2_widget.GetIntValue('achievementAge'));
    var currentDate = core_v2_utility.CurrentDate;
    var evalDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 0, 0, 0);
    var achID = context_v1_achievementAutomation.AchievementID;
    
    if(unit === 'y')
    {
       evalDate.setFullYear(evalDate.getFullYear() - achievementExpiry);
    }
    else if (unit === 'd')
    {
        evalDate.setDate(evalDate.getDate() - achievementExpiry);
    }
    else return;
    
    var pageIndex = 0;
    var done = false;
    while(!done) {
        var users = core_v2_user.List({
           SortBy: 'JoinedDate',
           SortOrder: 'Ascending',
           PageSize: 100,
           PageIndex: pageIndex
        });
    
        for(var i = 0; i < users.Count; i++) {
            var hasAchievement = context_v1_achievementAutomation.IsAwarded(users[i].Id);
            
            if(users[i].JoinDate !== null) {
                if (hasAchievement) {
                    var userAchievementResponse = core_v2_userAchievement.Get(achID, users[i].Id);
                    var achievementCreatedDate = userAchievementResponse.CreatedDate;
                                    
                    if( achievementCreatedDate  <= evalDate) {
                        context_v1_achievementAutomation.Revoke(users[i].Id);
                    }
                }
            }
                
        }
        
        if(users.TotalCount <= 100 * (pageIndex + 1)) {
            done = true;
        }
        
        pageIndex++;
    }

    And the Stack trace:

    UnknownException: An error occurred while rendering the 'Execution' script for the automation 'Test Certification (Revoke after Specified Time)' (384f02fd4592475f92e68ff80efb5691) (An error occurred while trying to render a widget. Details of the issue were logged for review by the administrator.) ---> Telligent.Evolution.ScriptedContentFragments.Model.JavaScriptException: Line 36, Column 16: TypeError: No public methods with the specified arguments were found.
     at Get(achID, Jint.Parser.Ast.MemberExpression) @  46:36
     at call(Jint.Parser.Ast.ThisExpression) @  0:1
     ---> Jint.Runtime.JavaScriptException: No public methods with the specified arguments were found.
       at Jint.Engine.Execute(Program program, JintCallStack callStack)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.ExecuteJavascript(JavascriptExecutionContext context, String resourceName, DateTime sourceLastModifiedDateUtc, Func`1 getSource, ScriptLanguage parentLanguage)
       --- End of inner exception stack trace ---
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.ExecuteJavascript(JavascriptExecutionContext context, String resourceName, DateTime sourceLastModifiedDateUtc, Func`1 getSource, ScriptLanguage parentLanguage)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.<>c__DisplayClass47_1.<RenderScriptInternal>b__0()
       --- End of inner exception stack trace ---
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.<>c__DisplayClass47_1.<RenderScriptInternal>b__0()
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentOutputCachingService.Get(ConfiguredAutomation configuredAutomation, Func`1 getRenderedOutput)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.RenderScriptInternal(ConfiguredAutomation configuredAutomation, IPropertyTemplateOptions propertyOptions, String templateName, ScriptLanguage language, Nullable`1 cancellationToken, String friendlyTemplateName, IDictionary`2 additionalContext)
       at Telligent.Evolution.ScriptedContentFragments.Implementations.ScriptedContentFragmentRenderingService.RenderScript(ConfiguredAutomation configuredAutomation, Nullable`1 cancellationToken)
       at Telligent.Evolution.Platform.Automations.Implementations.AutomationExecutionService.<>c__DisplayClass10_0.<Execute>b__0()
       at Telligent.Evolution.Api.Services.UserService.RunAsUser(Action a, String username, Nullable`1 userId, Nullable`1 membershipId)
       at Telligent.Evolution.Platform.Automations.Implementations.AutomationExecutionService.Execute(TextWriter writer, ConfiguredAutomation configuredAutomation, AutomationTriggerContext triggerContext, Nullable`1 cancellationToken, Boolean throwExceptions)
       at Telligent.Evolution.Platform.Automations.Implementations.AutomationJob.Execute(JobData jobData)
Children