Hi all. I'm having a bit of trouble figuring out how to accomplish something.
Basically, I have an InfoPath 2007 form being submitted to a MOSS 2007 Form Library. I originally set this up to use a Title field that's on the form itself as the document title when the form is submitted. This "seemed like a good idea at the time" (TM).
Now, though, I realize that if someone ever names their form the exact same thing as any other form, it will overwrite the old one, not make a new on with the same title. This strikes me as "Not a Good Idea" and so I am trying to fix it.
My thought is that I would create a second connection to the SharePoint form library to receive data, and set it to retrieve only the titles of all the documents. Then in the updated event of my title field, check whether there is a duplicate title name and raise a validation error if that's the case. I'm having some difficulty in figuring out how to handle the xpath stuff to make this happen, as I really don't know xml or infopath all that well.
Here's my code:
public void Title_Changed(object sender, XmlEventArgs e)
{
// Write your code here to change the main data source.
XPathNavigator xnMyForm = this.CreateNavigator();
XmlNamespaceManager ns = this.NamespaceManager;
string sNewTitle = xnMyForm.SelectSingleNode("/my:ChangeRequest/my:HeaderInfo/my:Title", ns).Value;
DataConnection TitleConnection = this.DataConnections["RFC_Titles"];
TitleConnection.Execute();
string sExistingTitle = xnMyForm.SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Request_For_Change[@Title = '" + sNewTitle + "']/@Title", NamespaceManager);
// if there WAS a result returned, raise an error
-->Add if statement here to check this
this.Errors.Add(TitleField, "TitleError", "The RFC Titlte Must be Unique.");
// else, if there was not, make sure there is no error
-->figure out how to do this right also
try
{
this.Errors.Delete("TitleError");
}
catch { }
}
Can anyone offer any suggestions? Am I on the right track? Is there a much much easier way to do this that I'm not thinking of?
Thanks!!!