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 = "document.write('<IMG SRC=/mynotesdb.nsf/" + section1 + "?OpenImageResource>" + "<BR/>')"
OutStr= "document.write('<a href=/mynotesdb.nsf/Features/" + Doc.UniversalID + " class=mainfeature>" + section + MyDocs + "</A><BR/>')"
UNID= "document.write('<a href=/mynotesdb.nsf/Features/" + Doc.UniversalID + " class=feature>" + section2 + " </A><IMG SRC=/mynotesdb.nsf/item_arrow.gif?OpenImageResource><BR/>')"
BAR = "document.write('<HR WIDTH=100% SIZE=4 ALIGN=left COLOR=0099CC NOSHADE>')"
Print Picture
Print OutStr
Print UNID
Print BAR
Set Doc = View.GetNextDocument(Doc)
End If
count = count + 1
Loop
End Sub
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 = "document.write('<IMG SRC=/mynotesdb.nsf/" + section1 + "?OpenImageResource>" + "<BR/>')"
OutStr= "document.write('<a href=/mynotesdb.nsf/Features/" + Doc.UniversalID + " class=mainfeature>" + section + MyDocs + "</A><BR/>')"
UNID= "document.write('<a href=/mynotesdb.nsf/Features/" + Doc.UniversalID + " class=feature>" + section2 + " </A><IMG SRC=/mynotesdb.nsf/item_arrow.gif?OpenImageResource><BR/>')"
BAR = "document.write('<HR WIDTH=100% SIZE=4 ALIGN=left COLOR=0099CC NOSHADE>')"
Print Picture
Print OutStr
Print UNID
Print BAR
Set Doc = View.GetNextDocument(Doc)
End If
count = count + 1
Loop
End Sub