Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with Agent Construction

Posted on 2004-09-20
10
Medium Priority
?
246 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
Independent Software Vendors: 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Loops Section Overview
Suggested Courses

610 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