Solved

Help with Agent Construction

Posted on 2004-09-20
10
236 Views
Last Modified: 2013-12-18
I have limited Notes scripting knowledge.
Can someone give me the steps to creating an agent that watches a mailbox for any message containing the text "CBS News" in the SUBJECT and then puts the BODY of that message in a file called "news.txt" on my C: drive.
Please be fairly specific.
thanks
0
Comment
Question by:rbender
10 Comments
 

Expert Comment

by:tsrconsultant
ID: 12132080
First:  Create a new agent and in the agent properties, select under runtime --> Trigger (On Event) and select AFTER NEW MAIL HAS ARRIVED.

This agent will then automatically run right after mail has arrived in your mailbox.  Now, to the agent:

Sub Initialize
      Dim db As notesdatabase
      Dim session As New NotesSession
      Dim doc As notesdocument
      Dim collection As NotesDocumentcollection
      Dim mysearch As String
      Dim rt As NotesRichTextItem
      
      Set db=session.currentdatabase

      filen$="\home\john\news.txt"

      'get any emails that have not been processed -- usually just one
      Set collection=db.unprocesseddocuments
      For x=1 To collection.count
            Set doc=collection.getNthdocument(x)
            Set rt=doc.getFirstItem(body)
            'get the text of the body
            mysearch=rt.getUnformattedText
            If Instr(mysearch,"CBS News",5)>0 Then
                  'lets send this message to the hard drive
                  fileNum% = Freefile
                  whenNow$ = Today()
                  Open filen$ For Append As fileNum%
                  Print #fileNum%,"Entry Created on: "+whenNow$
                  Print #fileNum%,mysearch+Chr(0)
                  Close #fileNum%                  
            End If
      Next
End Sub


** The problem we have here is that the AGENT will run on the server, so you have two choices on getting access:

#1.  Have the domino program write a file in a shared space or your home directory on the server:  example: if your username is john and you are on a linux type server you would replace the filen$ above to:  "/home/john/news.txt" -- you also may need to get the admin to allow the user 'notes' to access your home directory.

#2.  Have your admin map a drive to a shared folder on your computer and update the filen$ to represent that.  Your admin should be able to provide you with the proper path.
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 12133971
Or, alternatively, keep a local replica of your mail file, and turn on the User Preference to allow local scheduled agents.  Then you can schedule the agnet to run on your PC.
0
 

Author Comment

by:rbender
ID: 12145929
tsrconsultant:

The agent Initialize code won't get accepted.
Keeps alerting me and putting the cursor on :

      mysearch=rt.getUnformattedText


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:rbender
ID: 12158162
ping
0
 
LVL 7

Expert Comment

by:BarryTice
ID: 12191735
Change the line to:
mysearch = rt.GetUnformattedText(False, 80)

That should work for you.

-- b.r.t.
0
 
LVL 7

Expert Comment

by:BarryTice
ID: 12191900
Actually, the code above searches for "CBS News" in the body, not the subject. That's not what you wanted.

Try this code instead:

Sub Initialize
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim item As NotesItem
      Dim rtItem As NotesRichTextItem
      Dim intFile As Integer
      Dim whenNow As String
      
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      Set doc = dc.GetFirstDocument
      
      whenNow = Today()
      
      Do While Not (doc Is Nothing)
            Set item = doc.GetFirstItem("Subject")
            If Instr(item.Text, "CBS News") > 0 Then
                  intFile = Freefile
                  Open "C:\CBS.txt" For Append As #intFile
                  Print #intfile, Chr$(13)      ' Carriage return
                  Print #intfile, "Data added " & whenNow
                  Set rtItem = doc.GetFirstItem("Body")
                  Print #intfile, rtItem.GetUnformattedText(False, 80)
                  Close #intfile
            End If
            Set doc = dc.GetNextDocument(doc)
      Loop
End Sub

As mentioned above, if your mail is on the server and you get permission to run it there, you're still going to have problems. Chief among these problems is that it won't know your C:\ drive from anybody else's. That, in and of itself, is enough reason to not take the "After Mail Arrives" approach for something like this, especially as getting updates from CBS News is _probably_ not part of your official job requirements, and having to do extra work for you to be able to do non-work-related stuff probably won't be high on your sysadmin's list. Or, work locally, as qwaletee suggests.

It might be easier (though certainly less automated) to have the above script in an agent that you run manually from the actions menu against All Unread Documents in View. Then you could run the script throughout the day as you see fit before going to look into the CBS.txt file for what Dan Rather is saying these days.

-- b.r.t.
0
 
LVL 7

Accepted Solution

by:
BarryTice earned 50 total points
ID: 12191938
OK, my mistake (based on tsrconsultant's mistake): There is no GetUnformattedText method for a NotesRichTextItem. Use either rtItem.GetFormattedText(False, 80) to get the text formatted into 80-character lines, or rtItem.Text to get the raw text.

-- b.r.t.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now