Hi,
Sorry I had to jump on something else yesterday.
I used the _Changing event as it's the only one of the 3 that has an e.CancelableArgs (which I think I need?!).
Ideally, what I want is prevent duplicate participants, no matter what role they play in the process. I haven't been able to create a validation rule because I'm dealing with people pickers, so obviously some user feedback is desirable, which I could do through MessageBox.Show. So I rewrote my method as follows and it works ONCE.
Sequence: I had Person A, B and C as participants. Change Person C for person A. fires the error and resets to C. Change for person B and error does not come up.
string prevParticipantId = string.Empty;
string prevParticipantName = string.Empty;
public void participant_AccountId_Changed(object sender, XmlEventArgs e)
{
XPathNavigator xn = this.MainDataSource.CreateNavigator();
switch (e.Operation)
{
case XmlOperation.Delete:
prevParticipantId = e.Site.Value.Trim();
prevParticipantName = e.Site.SelectSingleNode("../pc:DisplayName", NamespaceManager).Value.Trim();
break;
case XmlOperation.Insert:
XPathNodeIterator xni = xn.Select("//my:review[my:reviewRequired = 1 and (my:ppicker/pc:Person/pc:AccountId = '" + e.Site.Value.Trim() + "')]", NamespaceManager);
if (xni.Count > 1)
{
MessageBox.Show("This person is already in use. Please try again." );
e.Site.SetValue(prevParticipantId);
e.Site.SelectSingleNode("../pc:DisplayName", NamespaceManager).SetValue(prevParticipantName);
e.Site.MoveToNext();
}
break;
case XmlOperation.ValueChange:
prevParticipantId = string.Empty;
prevParticipantName = string.Empty;
break;
default:
break;
}
}