Solved

Help with Agent Construction

Posted on 2004-09-20
10
244 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

690 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