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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a Random Document from a View

Status
Not open for further replies.

Jasterace

Programmer
Nov 27, 2003
1
DE
Hello! Hope this is in the best place:

I use the agent below to pull each document from the view "MainFeature" and then format certain fields in that document as HTML using the "document.write" command. I use it to place news items and editorial features on our website. I want to modify this agent to count the number of documents in the view and then pull just one of them based on that number. I think I can replace the Set Doc = View.GetFirstDocument command with Set doc = view.getNthDocument(i+1)command, but I need help to count the number of documents in the view and then generate a random number to use to put in the getNthDocument line.

The desired end result is to have a changing main article from a certain view so that when the site is visited, the content is always changing. I have tried hard to achieve this, but as Notes and Domino is not my primary job, I have so far had no luck - help greatly appreciated!

Sub Initialize
Dim session As New NotesSession
Dim i,j,count As Integer
Dim db As NotesDatabase
Set db = session.currentdatabase
Set View = db.GetView("MainFeature")
Dim Doc As NotesDocument
Dim Picture, OutStr, UNID, BAR As String
Dim section, section1, section2, As String


Set Doc = View.GetFirstDocument
Print "Content-type: text/js" 'Prevents Domino from generating stuff
Do Until doc Is Nothing
If doc Is Nothing Then
Else
section = Doc.MainItemHeading(0) 'Heading
section1 = doc.MainItem(0) 'Graphic to be used
section2 = doc.MainItemText(0) 'Catchphrase
Picture = &quot;document.write('<IMG SRC=/mynotesdb.nsf/&quot; + section1 + &quot;?OpenImageResource>&quot; + &quot;<BR/>')&quot;
OutStr= &quot;document.write('<a href=/mynotesdb.nsf/Features/&quot; + Doc.UniversalID + &quot; class=mainfeature>&quot; + section + MyDocs + &quot;</A><BR/>')&quot;
UNID= &quot;document.write('<a href=/mynotesdb.nsf/Features/&quot; + Doc.UniversalID + &quot; class=feature>&quot; + section2 + &quot; </A><IMG SRC=/mynotesdb.nsf/item_arrow.gif?OpenImageResource><BR/>')&quot;
BAR = &quot;document.write('<HR WIDTH=100% SIZE=4 ALIGN=left COLOR=0099CC NOSHADE>')&quot;
Print Picture
Print OutStr
Print UNID
Print BAR
Set Doc = View.GetNextDocument(Doc)
End If
count = count + 1
Loop

End Sub
 
I would suggest putting all docs in a collection (notesdocumentcollection). You have the property
Code:
Count
that tells you how many docs are in the collection, and you have the function
Code:
GetNthDocument
that allows you to retrieve a specific document in the collection.

Pascal.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top