logo

Ten Years On And Still Learning -- Notes Agent Data Stores

Rob Shaver replied to yesterday's post about using the LastRun property of Scheduled Notes Agents with an another, even better, alternative.

It turns out that Scheduled Agents have their own document/storage area that you can add to and read from. I never knew that!

You get to it via the SavedData property of the Session object (in LotusScript). See help page on it for more.

With a bit of tweaking I re-wrote the code I mentioned yesterday to more accurately find the documents created since it last ran, which is posted below.

This gets round the fact that the agent's LastRun property is the time it last finished. Any documents created while it ran won't ever get processed. Using the agents "saved data" area we can add a more reliable time to state when it began.

 

Set thisAgent = Session.currentAgent
Set agentDoc = Session.SavedData
        
Dim query As String, datepart As String
        
'Default date string
datepart = "@Adjust(["+Cstr(thisAgent.LastRun) +"];0;0;0;0;0;-30)"
        
If thisAgent.HasRunSinceModified Then
 If Not agentDoc Is Nothing Then
  If  agentDoc.HasItem("LastBeganAt") Then
   datepart = "["+Cstr(agentDoc.LastBeganAt(0))+"]"
  End If
 End If
Else
 datepart = "@Adjust(@Now; 0; 0; -1; 0; 0; 0)"  
End If
        
query = {Form="post" & @Created>=}+datepart+{ & Approved="0"}
        
agentDoc.LastBeganAt = Now 'Set this after query is built!
        
Set collection = db.Search(query, Nothing, 0)

'do stuff here

agentDoc.Save(True, True)

Forever Learning

How long have I been using Notes now!? Must be getting on for, if not more than, ten years. How this nugget passed my by I don't know. Going back to Monday's whine this is an example of one of the things I do love about this site. Without it I wouldn't know half what I do. The learning process is two-way! Thanks Rob.

Comments

    • avatar
    • Ed Lee
    • Thu 25 Jun 2009 04:39 AM

    Great post Jake and great tip Rob.

    Something I never knew about and will be very handy.

  1. Be careful about fiddling with the agent data notes. They can go orphan at the drop of a hat (http://www-01.ibm.com/support/docview.wss?rs=0&uid=swg24004199) and cause all kinds of interesting problems. I would use a profile document instead.

  2. And even better, if you switch agent profiling on, its saved as a profile document which you can then pick up programmatically. Its in one of my presentations somewhere, easy enough to reverse engineer.

    Handy for harvesting run-times, etc.

    ---* Bill

  3. I had a little experiment with SavedData in the early days of my blog. This was in regard to caching on the web.

    If anyone reading is considering the same, there are some things you need to consider.

    http://dontpanic82.blogspot.com/2007/10/notessessionsaveddata-great-for-wqo.html

    --

    All I seem to add to you blog lately Jake, are shameful plugs. Sorry about that..

    I'm in the situation you described earlier. I need to find areas that are interesting to both my readers -and- me. There's new ground to be conquered (XPages), but unless I start working with XPages applications at my job, I'm not going to learn enough to feel it's worth sharing. Here's hoping :)

  4. What's wrong w/ creating a custom field on the document for it's status?

    -- The absence of the field could indicate that it's a new document.

    -- Setting the field's value to 1 could mean some initial state, like "processed".

    If you then create a view of documents who's "status" field was absent and you then have a handy list of documents on which to run your agent, without the overhead of creating/maintaining a document collection. When your agent is done processing each document, the last step would be to set the "status" field's value to "1".

    With this approach, it doesn't matter what time the agent last ran, or completed, or even what documents were created while it ran.

    Even if you had 1m documents, that would only be 1MB of data used by the extra field.

    Am I oversimplifying things and missing the point, entirely?

    • avatar
    • Jake Howlett
    • Thu 25 Jun 2009 08:20 AM

    Nothing wrong with that approach MacDork. Seems a better one to me. Just not what came to mind when I first implemented this. Always more than one way to skin a ....

  5. Ahh. Delightful. I was hoping I hadn't been missing something all these years!

    Keep up the great work, btw. I lurk on your blog and read it regularly through rss. Thanks for the hard work you put into it.

  6. Another option is to store data in the agent design document itself. This has the advantage of being accessible from outside the agent and the values can then be included in a view. I am using this as a way of showing the date/time each agent last ran to those who do not have Designer level access to the database.

    • avatar
    • Jake Howlett
    • Thu 25 Jun 2009 11:11 AM

    "store data in the agent design document"

    Isn't that what I'm doing Peter? If not, please expand on how.

  7. I think he's referring to the "get design doc by NotesNoteCollection"-method.

    The SavedData-document gets deleted/recreated when you modify the agent. The design document is the same until you delete the agent.

    Example:

    http://www.lotusgeek.com/LotusGeek/LotusGeekBlog.nsf/d6plinks/ROLR-5NU4QB

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Thu 25 Jun 2009

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content