Selecting only the first document in a view

285 pts.
Tags:
Domino 6.5
Lotus Notes 6.x
Lotus Notes Database
I've created a view which shows all the documents created with a form. But does anyone know how I can extract info from just the first returned document? I'm creating a news module, and I just want to extract the first (latest) news story to put on a splash page. Does anyone know how I can either: a) just extract the first document? b) add criteria to the view selection to only return one (re: most recent) document? Thanks -mrg.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Have you looked at the GetFirstDocument method of the NotesView class?

—ADDED FROM DISCUSSION—-
AGENT CODE – In the Initialize event – not Globals – this is Lotuscript

Dim session as New NotesSession
Dim db as NotesDatabase
Dim view as NotesView
Dim doc as NotesDocument

‘initialize DB object
Set db = session.currentdatabase

‘initialize view document, replace YOURVIEW with the view name or alias
Set view = db.getview( “YOURVIEW” )

Set doc = view.getfirstdocument()

……do processes against the doc object – it is the first document in the view…..

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Mrg
    Do you think you could explain how the GetFirstDocument method works? Right now I have a View with a View Selection of SELECT (Form = "createNews") which lists all the documents. But then in the "Globals" section, do I add in the GetFirstDocument method? or how does it work?
    285 pointsBadges:
    report
  • SlikTool
    I think this was just a matter of teaching you to fish rather than give you one. If I understand correctly you have a view and you want to automate the grabbing of the first document. The code below will give you that, and it should work from an agent. But your response raises a new question, do you want this from an automated agent so it happens automatically, or do you want it to work from a view using an action button? AGENT CODE - In the Initialize event - not Globals - this is Lotuscript Dim session as New NotesSession Dim db as NotesDatabase Dim view as NotesView Dim doc as NotesDocument 'initialize DB object Set db = session.currentdatabase 'initialize view document, replace YOURVIEW with the view name or alias Set view = db.getview( "YOURVIEW" ) Set doc = view.getfirstdocument() ......do processes against the doc object - it is the first document in the view..... Mike Kinder mkinder@acadiasolutions.com
    1,840 pointsBadges:
    report
  • Mrg
    I'm all about learning how to fish! Just my lotusscript skills are almost non-existent. Ok, I've created an agent called, "getYerFirstdoc". I've used the code as indicated, using my Viewname, "newsStories". I've also scheduled it to run once an hour, between 8am and 6pm, as well as including in the Document Selection, the formula,
    Select (Form = "createNews")
    I guess my next question is, where does the
    doc
    variable, or it's result, get returned to? Or how can I access it's properties/fields inside it? How can I access this from a form?
    285 pointsBadges:
    report
  • SlikTool
    In the code I provided, the variable doc is the object is in. So in other words, doc contains all the properties and fields of the Document (the first document in the view you specified). To access fields in the document you can use references like: doc.fieldname(0) (where fieldname is the name of the field, and the (0) bit indicates the value in the field you want). If it is a single value field you still have to use the (0) bit to indicate the first value. If it is a multivalue, you may use other bits like (1) or (2). But generally you want to get the NotesItem object to represent the field and traverse the values to find the right one. I could likely spend hours on NotesDocument objects and NotesItem objects, but the help files are pretty good. In order for you to move forward with the provided code, you need to know that doc (the last line of the code) is a NotesDocument object. In the Designer, as you type code if you put "doc." (without the quotes) and wait you will get a list of properties and methods (though not fields). If you pick a property or method and put the "(" at the end of it and wait, the required parameters will show as well. Try some stuff and if you get stuck on something specific I will try to help. Mike Kinder michael.kinder@virtualmanagedsolutions.com
    1,840 pointsBadges:
    report
  • Mrg
    Ok, that definitely makes sense now. I see what you're saying. Although I'm still stuck on how to grab the result of the agent. Or how do I pass the result of the agent, into a form? I was thinking I could add this into the "WebQueryOpen" of my news display form.
    @Command([ToolsRunMacro]; "getYerFirstdoc")
    but that just provides an error when viewing on the web. And then, I guess I should be asking, in a form document, where would I put the code to access the variable doc.fieldname(0) ? Can I put this into a field or a computed text, with a default value of
    doc.fieldname(0)
    ? thanks again!! (in the meantime, back to the help files...)
    285 pointsBadges:
    report
  • Brooklynegg
    Mrg: Am I right to assume you have no experience developing for Notes/Domino? In that case, I'm not sure where to start. There are so many ways to do what you are attempting that it becomes difficult to address the question. However, you state that you want to display information on a form and your latest statement implies that you are familiar with fields and computed text. You also never state that you want to save the value in a record for use in a report, or display it in a Notes view, just display it on the form. I would recommend that you use a computed for display field with an @Dbcolumn formula to get all the values in the view you are refering to, have those values assigned to some variable (e.g. ResultList) then wrap that in @subset(ResultList; 1) to get its first value. Be sure to use the [failesient] option so no error is returned if the view has nothing in it. That is an @Formula version of a solution, rather than LotusScript. If you are a Visual Basic wizard and prefer to stay on that track, then SilkTool can keep you going down that path. LotusScript is a perfectly viable option, especially if Basic is you strength and you want to build a set of re-usable components in a script library. (Note to general readers of this thread: An actual request like this in my past included a requirement to see the first 4 items by default, links to see bring up the next 4 items, and an option to see all the items in the view. The solution involved a $$ViewTempate form, $$ViewTitle field, an initial URL that made only the first 4 items display, and computed text below the $$ViewBody field display that provided the "Page 1", "Page 2", "Page 3" and "all items" links. Because Mrg's request is so specific to displaying only the one most recent item, and because of his apparent unfamiliarity with Notes/Domino, I didn't want to get into the broader options for using Domino objects on the web.)
    3,845 pointsBadges:
    report
  • SlikTool
    I think I get it now. This is clearly a Web based application, correct? If my assumption is correct, then the following may help. No you cannot point doc.fieldname(0) to a computed text object. You may want the WebQueryOpen agent to build the web page completely - OR you can use computed for display fields in place of computed text (must use form here rather than a page element). In the webqueryopen agent use the session.documentcontext object to represent the newly created document (webpage) that is being populated by the document you grab from the view. For example. Dim session as New NotesSession Dim db as NotesDatabase Dim view as NotesView Dim wDoc as NotesDocument 'current web document with the Webqueryopen agent Dim doc as NotesDocument 'document retrieved from the view Set wDoc = session.documentcontext ‘initialize DB object Set db = session.currentdatabase ‘initialize view document, replace YOURVIEW with the view name or alias Set view = db.getview( “YOURVIEW” ) Set doc = view.getfirstdocument() with wDoc .newField1 = doc.fieldName1(0) .newField2 = doc.fieldName2(0) etc....... end with Without more specifics there is no way I can help further. I have not tried this specifically but it may need some tweaking. I know the WebQueryOpen agent has some limitations - but it should work. Just have the form made the way you want it with the fields that need populated. The agent should populate their values before the document (from the web form) is converted to HTML. ---STRAIGHT FROM HELP---- WebQueryOpen events A WebQueryOpen event runs the agent before Domino converts a document to HTML and sends it to the browser. IBM® Lotus® Domino(TM) ignores any output produced by the agent in this context. Examples for using this agent include performing large computations that aren’t possible with @commands or collecting statistics about who opened documents and when they did so. Note WebQueryOpen agents run when the user opens a form or document, but do not run when the user saves a document. This means that computed fields set by a WebQueryOpen agent are not saved when the user submits a document. To make sure computed fields are saved, you can either recalculate them in the WebQuerySave agent or set the form property "Generate HTML for all fields."
    1,840 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following