Project Server 2007 Event Handlers

A

Andrzej Jaworek

Hi All,
Based on this article:
http://msdn2.microsoft.com/en-us/library/bb802729.aspx
I've created an event for adding a new task. Before adding a new task
(via My Task-> New -> Task) after clicking Send button on adding new
task form, my event code cheks some conditions and set e.Cancel =
true/false based on my conditions.

To do this I've created a class:
public class TaskCreatingEventHandler : StatusingEventReceiver
{
public override void OnTaskCreating(PSContextInfo contextInfo,
StatusCreateTaskPreEventArgs e)
{
base.OnTaskCreating(contextInfo, e);

//here I have my conditions.
//If my conditions are not passed I'm setting
//e.Cancel = true





}
}

On Server-Side Event Handler Configuration in PWA I've attached this
program to Statusing > TaskCreating event.

After making sure that the event is installed, I've run Visual Studio
debugger, attached to the process and set breakpoint on the begining of
the OnTaskCreating method.
After that I've clicked on My Task then New, then Task. On adding a new
task form I've filled all required fields (I've entered values that do
not pass my conditions) and clicked Send. VS Debuger has stoped on my
breakpoint.
I've went through the whole code step by step to check if my conditions
are working fine. Everything was fine : e.Cancel = true is set. After
finishing running the whole code I've returned to the PWA and realised
that the red info was displayed on the adding new task form. I was sure
that everything was ok and that the new task was not added. But when
I've returned back to the My task directory I've seen that my task was
added and was visible on the My task grid.

Why? How to cancel adding a new task via event handler?
Please help.

Andy
 
A

Andrzej Jaworek

Nobody can help me ?? Please, please. :(
Resolving this problem is very immportant for me.

Andy
 
M

Maik

Andrzej Jaworek said:
Nobody can help me ?? Please, please. :(
Resolving this problem is very immportant for me.

Andy

Hi Andy,

your code looks fine so far, my code for other events looks the same except
the base method (refer to the sdk you can delete this method:
http://msdn2.microsoft.com/en-us/library/ms469450.aspx Procedure 2 . 2)
I don´t think that this will cause the prob, but who knows.

Till now i haven´t used the OnTaskCreating event, maybe someone else can help.

if you find the prob, let us know :)

Greets
Maik
 
A

Andrzej Jaworek

Maik pisze:
Hi Andy,

your code looks fine so far, my code for other events looks the same except
the base method (refer to the sdk you can delete this method:
http://msdn2.microsoft.com/en-us/library/ms469450.aspx Procedure 2 . 2)
I don´t think that this will cause the prob, but who knows.

Removing base.OnTaskCreating(contextInfo, e) from OnTaskCreating event
didn't help :( I have no idea how to cancel creating task from code :(:(

Andy
 
K

Kit

Don't you need to set e.cancel = true BEFORE you call
"base.OnTaskCreating(contextInfo, e);" ?
 
M

Maik

Hi,

with e.Cancel = true; you cancel creating task, and you´ve to set this
before you call the base method (if you use this method). But you wrote that
you tried to delete the base method (refer to the SDK), so this shouldn´t be
the prob. Are you sure that your conditions are not passed and e.Cancel is
set to true ?

If you call the base method in your code, make sure to call it at the end of
your code.

Greets
Maik
 
A

Andrzej Jaworek

Maik pisze:
Hi,

with e.Cancel = true; you cancel creating task, and you´ve to set this
before you call the base method (if you use this method). But you wrote that
you tried to delete the base method (refer to the SDK), so this shouldn´t be
the prob. Are you sure that your conditions are not passed and e.Cancel is
set to true ?

If you call the base method in your code, make sure to call it at the end of
your code.

I've tried may probs, with base.OnTaskCreating(contextInfo, e) method,
without it, setting e.cancel = true before base method and after base
method. I always had the same result: task was not cancelled and it was
seen on My Task site after adding task :(.
 
M

Maik

Hi Andy,

maybe this is a double post. I replied some hours ago, but i can´t see my
posting here. So once again :)

When you add a new task from the MyTask -> New Task page, a message will be
sent to your PM. He/She must reject this task, after

that you can see the canceled task on your MyTask page and you can delete it
yourself. This happens regardless if your EventHandler cancel the event or
not.

I tried it myself, my EventHandler write some data to the eventlog and set
e.Cancel = true;. I can see the 2 expected entries in the Eventlog: 1.

Type Error Source Office Sharepoint Server Category Project Server
Server-Side Events and 2. my own entry Type Information.

After canceling a message appears on the page that the event was canceled by
an event handler, but i can see the new task on the MyTask page. The PM (in
this case myself) reject the new task, so that i can delete it on the MyTask
page.

Seems that this is the standard behavior, not very usefull i think...

Greets
Maik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top