Loggin custom activity in API doesn't work

Andrew Huchko asked on December 22, 2016 12:26

I created custom activity named like "MyCustomActivity":Contact management => Activity types => new activity type. Setted name as: My Custom Activity; Code name: MyCustomActivity. Enabled:true, manual creation:true; Activity class

public class MyCustomActivity : Activity
{
    /// <summary>
    /// Default constructor.
    /// </summary>
    /// <param name="variables">Environment variables required for proper logging of activities</param>
    public MyCustomActivity(ActivityContext variables)
        : base(variables)
    {
        Data.Title = "My Custom Activity";
    }

    /// <summary>
    /// The code name of the corresponding activity type in Kentico.
    /// </summary>
    protected override string ActivityType
    {
        get
        {
            return "MyCustomActivity";
        }
    }


    /// <summary>
    /// The code name of the settings key that determines whether the system logs the activity.
    /// </summary>
    protected override string SettingsKeyName
    {
        get
        {
            // The code name of the "Custom activities" setting (in Settings -> On-line marketing -> Contact management -> Activities)
            return "CMSCMCustomActivities";//in settigs this key set to true(checked)
        }
    }
}

In macro method I have the followin code:

MyCustomActivity act = new MyCustomActivity(AnalyticsContext.ActivityEnvironmentVariables);
act.Log();

It doesn't log any activity in Contact managment => Activity.

In dropdown activity appears. But when I run and debug my code, it doesn't log any activity.

CMS version: kentico 9.

License: EMS unlimited web sites.

Does it something with current contact?

I insert macro in System console and debug it. It looks like all is fine. But activity doesn't log.

In settings all checkboxes checked wich related to Activities

Correct Answer

Roman Hutnyk answered on December 22, 2016 13:10

I'd recommend to avoid calling a macro, that logs an activity, from macro console - that could be wrong context for this operation.

Try to call

MyCustomActivity act = new MyCustomActivity(AnalyticsContext.ActivityEnvironmentVariables); 
act.Log();

from web part for example, preferably on the live site.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Anton Grekhovodov answered on December 22, 2016 12:56

Hi Andrew,

The code is C# code, it's not K# macro expression, so you can't debug it (see result) in System > Macros > Console.

0 votesVote for this answer Mark as a Correct answer

Andrew Huchko answered on December 22, 2016 13:10 (last edited on December 22, 2016 13:23)

I'm sorry, I mean code inside macros:

[MacroMethod(typeof(string), "", 1)]
public static object ActivityMacro(EvaluationContext context, params object[] parameters){
    MyCustomActivity act = new MyCustomActivity(AnalyticsContext.ActivityEnvironmentVariables);
    act.Log();
}
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.