PDA

View Full Version : Use UIView to display view with hidden column



zhaoxyu
11 Aug 2009, 4:54 AM
If there are hidden columns in a view,the search plugin cannot work normal.I'll give a solution below

Alter the agent "extnd/3x/SearchView" in extnd_b2r2.nsf as below

Sub Initialize
%REM
This agent can be called from the web to search any view and return results in the
same format as the ?ReadViewEntries command. This was created for use with the
NotesView2 class v1.3 and above.
%END REM
Msgbox "开始搜索。。。"
On Error Goto ErrorHandler
Dim session As New NotesSession
Dim dbSearch As NotesDatabase
Dim colEntries As NotesViewEntryCollection
Dim vwSearch As NotesView
Dim entryResult As NotesViewEntry
Dim docCurrent As NotesDocument
Dim docResult As NotesDocument
Dim strQuery As String
Dim strDb As String
Dim strView As String

' variables for single category search
Dim strRTC As String
Dim intRTCAdjustment As Integer
Dim columnRTC As NotesViewColumn
Dim strRTCFormula As String

Dim intMax As Integer
Dim lngCount As Long, i As Long
Dim lngStart As Long, lngEnd As Long
Dim strParameters As String
Dim lngResults As Long
Dim tmpString As String
Dim x As Integer
Dim tmp As Integer 'add by zhaoxingyu

'start the xml document
Print "Content-Type:text/xml;"
Print "<?xml version=""1.0"" encoding=""GB2312""?>"

'first we get the search parameters out of the querystring
'db, vw, query, searchmax, count, and start
Set docCurrent = session.DocumentContext
strParameters = docCurrent.GetItemValue("Query_String")(0)
strDb = GetParameter("db",strParameters)
strDb = Replace(Strright(strDb,"/"),"/","\")
strView = GetParameter("vw",strParameters)

strQuery = GetParameter("query",strParameters)
intMax = 0
If Isnumeric(GetParameter("searchmax",strParameters)) Then intMax = Cint(GetParameter("searchmax",strParameters))
lngCount = 100
If Isnumeric(GetParameter("count",strParameters)) Then lngCount = Clng(GetParameter("count",strParameters))
lngStart = 1
If Isnumeric(GetParameter("start",strParameters)) Then lngStart = Clng(GetParameter("start",strParameters))

'now we get the view to search
Set dbSearch = session.GetDatabase("",strDb,False)
Set vwSearch = dbSearch.GetView(strView)

' check for RestrictToCategory because if one exists, we have to adjust the columnnumber attribute
' and we will need to tweak the strQuery to also search on the category
strRTC = GetParameter("RestrictToCategory",strParameters)
If (strRTC <> "") Then
intRTCAdjustment = 1
Set columnRTC = vwSearch.Columns(0) 'in a RestrictToCategory view, the first column, column 0, should be the category column
If columnRTC.IsFormula Then
strRTCFormula = columnRTC.Formula
Else
strRTCFormula = "FIELD " + columnRTC.ItemName
End If
strQuery = |(| + strRTCFormula + |="| + strRTC + |") AND (| + strQuery + |)|
Else
intRTCAdjustment = 0
End If

'now we run the search

lngResults = vwSearch.FTSearch(strQuery,intMax)

'now we spit out the results
Print "<viewentries toplevelentries=""" & Cstr(lngResults) & """>"
Set colEntries = vwSearch.AllEntries

'set the starting point for the loop
If lngStart > lngResults Then lngStart = lngResults

'set the ending point for the loop
lngEnd = lngStart + lngCount - 1
If lngEnd > lngResults Then lngEnd = lngResults

'now loop through the appropriate subset of results and print out a viewentry tag for each one
i = lngStart
tmp = intRTCAdjustment
While i <= lngEnd
Set entryResult = colEntries.GetNthEntry(i)
If Not entryResult Is Nothing Then
Set docResult = entryResult.Document
Print "<viewentry position=""" & Cstr(i) & """ unid=""" & Cstr(docResult.universalID) & """ noteid=""" & Cstr(docResult.NoteID) & """ siblings=""" & Cstr(entryResult.SiblingCount) & """>"
x = 0
intRTCAdjustment = tmp
Forall value In entryResult.ColumnValues
If Not vwSearch.Columns(x).isCategory Then
tmpString = ""
If vwSearch.Columns(x).IsHidden Then
intRTCAdjustment = intRTCAdjustment + 1
Else
tmpString = tmpString + "<entrydata columnnumber=""" & Cstr(x - intRTCAdjustment) & """ name=""" & vwSearch.Columns(x).itemName & """>"
tmpString = tmpString + "<text>" & XMLEscape(Cstr(value)) & "</text>"
tmpString = tmpString + "</entrydata>"
End If


Print tmpString
End If
x = x + 1
End Forall
Print "</viewentry>"
End If
i = i + 1
Wend
AtEnd:
Print "</viewentries>"

Exit Sub
ErrorHandler:
Print "<error>" & "Error in SearchView: " & Error & "---at " & Erl & "</error>"
Resume AtEnd
End Sub

jratcliff
11 Aug 2009, 5:00 AM
This doesn't work when the column is hidden by a "hide when formula" does it? I think I tried a solution similar to this and it works if the checkbox to hide the column is checked but if a hide when formula is used, .isHidden doesn't detect that.

jratcliff
17 Aug 2009, 9:05 PM
Fixed in Beta 3 (I'm pretty sure but please test using your own view with hidden columns).