Skip to main content
Dear all,

I followed the K2.net Studio SDK, created a Mail Server event template, then I created my own activity template (works fine), and tried to add the Mail Server template to it, but it doesn't work. K2 prompts out the following message:


I'm not sure the procedure that I added the event to activity is correct or not. In my activity, the Execute code is:

public bool Execute(K2Studio.Activity myActivity)
{
base.Initialize(myActivity);
myActivity.Description = this.MyTemplateDescription;
AddDataField(myActivity);
AddEvent(myActivity);
return true;
}


The AddEvent(myActivity) is:

public void AddEvent(K2Studio.Activity myActivity)
{
K2Studio.Event myEvent = myActivity.Events.AddServerEvent("My Event Template");
MyEventTemplate myEventTemplate = new MyEventTemplate();
//myEventTemplate.BuildEvent(myEvent);
myEventTemplate.Execute(myEvent);
}


The Execute code for the Event template is:

public bool Execute(K2Studio.Event myEvent)
{
// Set the event template type
//myEvent.Type = K2Studio.EnumEvent.Server;
PropertyTemplate.Instance = new PropertyTemplate();
//base.PropertyTemplateAssists.Add(PropertyTemplate.Instance);
//base.Initialize(myEvent);
//myEvent.Name = this.MyEventTemplateName;
myEvent.Description = this.MyTemplateDescription;
//PropertyTemplate.Instance.LoadData();

if (base.RunWizard(new TemplateWizard()) == System.Windows.Forms.DialogResult.Cancel)
{
// If no Data present, remove Event from Activity else Save it
if (!PropertyTemplate.Instance.HasData)
{
myEvent.Activity.Events.Remove(myEvent.Name);
}
else
{
base.SaveAll(true);
}
}
else
{
base.SaveAll(true);
}
return true;
}


I found the exception points are:
base.PropertyTemplateAssists.Add(...); base.Initialize(myEvent); PropertyTemplate.Instance.LoadData(); respectively.
When I commented out all these, the activity template can automate the Mail Server template, brings up the first page of the wizard form, but when I pressed "Next" to go further, K2 also prompts up the same error message.


Any help would be appreciated,
Cheers,
Patrick
Hi Patrick,

Might be a silly question but do the following succeed?

1. Adding your custom event to a standard K2 Studio activity.
2. Adding a standard K2 Event to your custom activity.

Therefore, the problem lies in the combination between your custom event and your custom activity?

Regards,
Graham
Hi Graham,

Thanks for your reply.
Yes, both cases work successfully, but the one I combined the customed event and customed activity doesn't. Any idea?


Regards,
Patrick
Hi Patrick,

Have a look at the following article:

http://www.ondotnet.com/pub/a/dotnet/excerpt/csharpckbk_chap01/index.html?page=2

and then code the try/catch round the code you think is failing, i.e. what you noted above. Set a breakpoint in the catch statement and one at the end of the normal processing.

I have a funny feeling it is the property template instance data load method, but I cannot tell you why - maybe that is where I had all my problems when I started with custom events, etc. Could you post your LoadData code?

Graham

Reply