Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering Records in MOSS 2007 Custom List

Status
Not open for further replies.

larrydavid

Programmer
Jul 22, 2010
174
US
Hello,

I am using VB.Net in Visual Studio 2010 and using web services to connect to SharePoint 2007 to retrieve custom list data. I can retrieve all records from the SharePoint custom list but when I try to filter out records and fields using the CAML fragments in the query and viewFields objects listed below, it does not filter either. I have tried many different variations (using “ows_” field name and without) to get a different query result but with no luck. It gets very strange when I use the viewFields object, it filters out the data listed in the viewFields object but leaves all the unwanted fields (I think it should work the other way). No error messages are returned. Each and every time, the results set returns all the records and fields in the list up to the RowLimit property as if the query and viewFields objects were not considered in the query. I have attached the code below. Any assistance to help resolve my dilemma would be greatly appreciated.
Code:
Private Function GetContractMainDataSet(ByVal cInConfiguratorName As String) As String
        clsFunctions.DisplayStatusMessage("Retrieving Records, please wait...", stMessage)
        Try
            Dim ds As New DataSet

            Dim cGUID_List As String = clsSP.cGUID_List_Configurator_Inventory_Log
            Dim cGUID_View As String = "{085BAED5-3F10-4885-A99F-E6A5FEB1881A}"

            Dim xmlDoc As XmlDocument = New XmlDocument
            Dim query As System.Xml.XmlElement = xmlDoc.CreateElement("Query")
            Dim viewFields As System.Xml.XmlElement = xmlDoc.CreateElement("ViewFields")
            Dim queryOptions As System.Xml.XmlElement = xmlDoc.CreateElement("QueryOptions")

            query.InnerXml = "<Query><OrderBy><FieldRef Name='Assigned Configurator' /></OrderBy>” & _
“<Where><Eq><FieldRef Name=""ows_Assigned Configurator"" />" & _
                    "<Value Type=""Text"">" & cInConfiguratorName & "</Value></Eq></Where></Query>"

            viewFields.InnerXml =  _
                "<FieldRef Name='Title' />" & "<FieldRef Name='ows_Column3' />" & _
                "<FieldRef Name='ows_Column4' />" & “<FieldRef Name='ows_Column5' />" & _
                "<FieldRef Name='ows_Config_User' />" & "<FieldRef Name='ows_Smoke_User' />" & _
                "<FieldRef Name='ows_Super_User' />" & "<FieldRef Name='ows_ID' />)")

            queryOptions.InnerXml = "<queryoptions><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" & _
                "<DateInUtc>TRUE</DateInUtc></queryoptions>"

            Dim cRowLimit As String = "90"
            Dim cWebID As String = ""

            Dim objCredentials As New NetworkCredential(clsSP.cUSID, clsSP.cPWID, "CS")
            Dim SPList As New WS_WGK_List.Lists
            With SPList
                .Credentials = objCredentials
                .Url = clsSP.cURL_Contract_List

                'Get the list of configurator specific items...
                Dim nodeSP As XmlNode = .GetListItems(clsSP.cGUID_List_Configurator_Inventory_Log, _
                    cGUID_View, query, viewFields, cRowLimit, queryOptions, cWebID)
                If Not nodeSP Is Nothing And nodeSP.InnerXml.Length > 0 Then
                    Dim reader As XmlTextReader = New XmlTextReader(nodeSP.OuterXml, XmlNodeType.Element, Nothing)
                    ds.ReadXml(reader)
                Else
                    '??? - Not sure what to do here...
                End If
            End With

            Dim nCnt As Integer = ds.Tables(1).Rows.Count
            If nCnt > 0 Then
                With dgvContracts
                    .DataSource = ds
                    .DataMember = ds.Tables(1).TableName
                    .Refresh()
                End With

                clsFunctions.DisplayStatusMessage("Ready...", stMessage)
            Else
                clsFunctions.DisplayStatusMessage("No Status Records Found...", stMessage)
                tmrMain.Interval = 5000
                tmrMain.Enabled = True
            End If

            Return Nothing
        Catch ex1 As System.Web.Services.Protocols.SoapException
            MsgBox("ERROR #1: " & ex1.Message, MsgBoxStyle.Critical, "SharePoint Data Error")
        Catch ex2 As Exception
            MsgBox("ERROR #2: " & ex2.Message, MsgBoxStyle.Critical, "Data Retrieval Error")
        End Try
    End Function

Thanks,
Larry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top