Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
Quickr My First Placebot - Move incoming Emails to a folder

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#PlacebotMoveEmail or http://www.notesninjas.com/A555F9/nn.nsf/ByAlias/PlacebotMoveEmail


Placebots allow users and developers to add code Quickr Places and Quickr Place templates.





This Placebot moves any emails in the index folder into another folder called "Emails In" .

This can be changed in the code.

The code can be fiddled to prevent the documents being reset to the folder all the time by storing a "ProcessedByInboxAgent" field on the document.

 

Option Public

Sub Initialize
' Placebot code by Adam Foster July 2008
' Please check http://NotesNinjas.com/#PlacebotMoveEmail for latest versions





Dim s As New notessession
Dim db As notesdatabase
Set db = s.currentdatabase
Dim v As notesview
Set v= db.GetView("System\Index")
Dim doc As notesdocument

fname="Emails In"
Dim vf As notesview
Set vf=db.GetView(fname)
If vf Is Nothing Then
 Print "Move emails Placebot: Cannot find folder '" & fname & "' in " & db.filepath
 End
End If

Dim agentlog As New NotesLog("AgentLog")
Call agentLog.OpenAgentLog

Set doc=v.GetFirstDocument()
Do Until doc Is Nothing
 If doc.HasItem("Sendto") Then
 
  'ok got one
  agentlog.logaction("checking " & doc.subject(0))
  If doc.HasItem("h_folderunid") Then
   'ok already in a folder
   If doc.h_folderunid(0) <> v.UniversalID Then
    agentlog.logaction("Changing " & doc.subject(0) & " to folder " & fname & " ... ")
    Call doc.replaceitemvalue("h_folderunid",v.UniversalID)
    Call doc.PutInFolder(fname)
    Call doc.Save(True,False)
    agentlog.logaction("Saved " & doc.subject(0) & " to folder " & fname)
   End If
   agentlog.logaction("document already has the h_folderunid field")
  Else
   agentlog.logaction("Moving " & doc.subject(0) & " to folder " & fname & " ... ")
   Call doc.replaceitemvalue("h_folderunid",v.UniversalID)
   Call doc.PutInFolder(fname)
   Call doc.Save(True,False)
   agentlog.logaction("Saved " & doc.subject(0) & " to folder " & fname)
  End If
 End If
 Set doc = v.GetNextDocument(doc)
Loop
Call agentLog.Close
End
eh:
agentlog.logaction("Error: " & Error$ & " at line " & Erl)
Call agentLog.Close
End
End Sub

 

Save the above code into a text file using notepad and call it MoveEmail.lss or something.

Create your folder "Emails In" or whatever you change fname to in the code above.

creat your placebot, and pick the lss file.

Set it to run every 10 minutes or so.

After saving, you can select the placebot, then do a "Run Placebot" from the more options action button.

Hope this helps you write more placebots. If so please share them with me.

 

 

 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Lotus Notes 5 All-in-one Certification Exam Guide by Libby Schwarz, Ben Malekzadeh
Sort out your CLP with this book.
See at: Amazon.co.uk | Amazon.com |