Wednesday, November 23, 2011

Lotusscript Scheduled Agents Run Afer Design Refresh

So, you go into designer and make a change to that huge agent that runs at 2am and imports 100,000 records from an external source.  Then, like all good developers, you push your update from your design template to the production database.  And a few minutes later, everyone is calling your Helpdesk because the file is running slow.  A quick check of the server and you find out that the agent started running for some reason.  Surprise!  It's an "undocumented" feature! 

What is happening is that after the agent is saved and put into your production database on your server, the information for that scheduled agent has run today is cleared out -- so it runs again.

So how can you stop this frustrating issue?  Add a notes INI file setting to your server:

Amgr_SkipPriorDailyScheduledRuns=1

This should stop your scheduled agents from running wild after you make adjustments to them.  This is a new feature starting with Domino 7.

If you would like to read more about this issue, look at this IBM link:  https://www-304.ibm.com/support/docview.wss?uid=swg21099248

Friday, November 11, 2011

Compare two Notes Databases

Have you ever found a need to check the records within two Notes databases (say two versions of your mail file)?  The below code will do that and place the differences into a folder called NOTFOUND.  You run this code from your source database against the target that you think is missing data.  Be sure to set this again to run against all records (i.e. not selected documents).

%REM
    Agent CompareMyDocs
    Created Nov 10, 2011 by David Scott
    Description:
        This agent will run from a source db and see if there are matching
        records in the destination db.  If not, a folder call NOTFOUND will
        be populated with these documents.
%END REM

Option Public
Option Declare

Sub Initialize
    Dim ses As New NotesSession
    Dim srcdb As NotesDatabase
    Dim srcnote As NotesDocument
    Dim srcview As NotesView

    Dim destdb As New NotesDatabase("", "mylocalfile.nsf")
    Dim destnote As NotesDocument
    Dim destview As NotesView

    Dim DocsRead As Integer
    Dim DocsNotFound As Integer
    Dim key As String       

    DocsRead = 0
    DocsNotFound = 0
           
    Set destview = destdb.GetView("($All)")       
   
    Set srcdb = ses.CurrentDatabase    'Run from the source file
    Set srcview = srcdb.GetView("($All)")           
    Set srcnote = srcview.GetFirstDocument
   
    While Not(srcnote Is Nothing)       
        DocsRead = DocsRead + 1
        key = srcnote.UniversalId

        Set destnote = Nothing
        On Error  Resume Next
        Set destnote = destdb.GetDocumentByUNID(key$)       

        If (destnote Is Nothing) Or (destnote.Isdeleted ) Then 'Not found or is a delete stub
            Call srcnote.PutInFolder( "NOTFOUND",True )
            DocsNotFound = DocsNotFound + 1   
            Print "No Matching record #" & DocsNotFound & " for UNID " & key$
        End If

        Set srcnote = srcview.GetNextDocument(srcnote) 'Go to the next document
       
    Wend
   
    MsgBox " Total Documents Read " & DocsRead & " Total Documents Not Found " & DocsNotFound

End Sub