Skip Ribbon Commands
Skip to main content

Ben There, Done That

:

SharePoint Ben > Ben There, Done That > Posts > Filtering an InfoPath field when using Forms Services
December 30
Filtering an InfoPath field when using Forms Services
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 posted on his blog at: http://www.sharepoint-tips.com/2007/01/infopath-form-services-implementing.html. The code posted by 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.
 

 Comments

 
 
 
 
 
 
 
 
 
 
 

Glad you liked it. Would you like to share?

Sharing this page …

Thanks! Close

Add New Comment

 

Showing 0 comments

    Trackback URL
     
    blog comments powered by Disqus
     

     Pre-Disqus Integration Comments

     

    Comments

    There are no comments for this post.