| For the same project I needed to delete an item from a SharePoint list, I also needed to filter data received from a SharePoint List. This is an easy thing to accomplish in a simple InfoPath form, however, if you need to make your form Forms Services compatible, the filter option in SharePoint isn't supported. To get around this issue, I used a nifty trick using C# code and SharePoint's ability to display a list in XML that Ishai Sagi posted on his blog at: http://www.sharepoint-tips.com/2007/01/infopath-form-services-implementing.html.
The code posted by Ishai Sagi was the following (all cod in italics must be replaced to match your form):
public void [Field]_Changed(object sender, XmlEventArgs e){
SetFilter();
}
private void SetFilter(){
FileQueryConnection q = (FileQueryConnection).DataConnections[InfoPath Data Connection];
q.FileLocation = q.FileLocation + "FilterField1=LinkTitle&FilterValue1=" + GetFilterValue();
q.Execute();
}
private string GetFilterValue(){
XPathNavigator nav = this.CreateNavigator();
string filterValue = (string)nav.SelectSingleNode("[Filter Field xPath]",this.NamespaceManager).ValueAs(typeof(string));
return filterValue;
}
It is easy to implement, even for non-developers (like myself), and I haven't discovered any downsides or problems with it yet. |