Subject: Create a mail rule in script
Posted by Alexandre Guerard on 30.07.2004 at 20:41 using a Web browser
Category: Domino Designer Release: 6.5 Platform: Windows 2000
Content:
Hi,
I want to create a mail rule using script when the database is open.
The script bellow verify if the Rules already exist and create if not.
1) In the Database Script, I verify if the rule exist and if not, I create the document
2) I pass the new Doc and I run the same code as the OK button in the New rules form. Call ButtonOKClient()
The rules get created but the problem is that it doesn't work.
Thank You
Alexandre
Database SCRIPT (Initialize):
Call SCISetJunkRule()
Sub SCISetJunkRule:
Sub SCISetJunkRule()
'// Verify if rules exist
Dim m_Session As New notessession
Dim m_Db As notesdatabase
Dim ViewEntry As Notesviewentry
Dim m_RulesView As notesview
Dim m_ViewCollection As NotesViewEntryCollection
Dim m_RuleDoc As notesdocument
Dim doc As NotesDocument
Set m_db = m_Session.currentdatabase
Set m_RulesView = m_Db.getview("Rules")
If m_RulesView Is Nothing Then Exit Sub
Set m_ViewCollection = m_RulesView.Allentries
If m_ViewCollection.count > 0 Then
Set ViewEntry = m_ViewCollection.Getfirstentry
While Not ViewEntry Is Nothing
Set doc = ViewEntry.Document
If Instr(doc.ConditionList(0),"[SPAM]") <> 0 Then
Exit Sub
End If
Set ViewEntry = m_ViewCollection.Getnextentry( ViewEntry )
Wend
End If
'//Find Highest Rules
Dim Highest As Integer
If m_RulesView Is Nothing Then Exit Sub
Highest = 0
Set m_ViewCollection = m_RulesView.Allentries
If m_ViewCollection.count > 0 Then
Set ViewEntry = m_ViewCollection.Getfirstentry
While Not ViewEntry Is Nothing
If highest < ViewEntry.Columnvalues( 1 ) Then
Highest = Cint( ViewEntry.Columnvalues( 1 ) )
End If
Set ViewEntry = m_ViewCollection.Getnextentry( ViewEntry )
Wend
End If
If Highest = 0 Then
Highest = 1
End If
'// Create rules
Dim exclude(1) As String
Dim FilterFormulaItem As NotesItem
Dim m_CalProfile As NotesDocument
Set m_CalProfile = m_db.GetProfileDocument("CalendarProfile")
Set FilterFormulaItem = m_CalProfile.getfirstitem("$FilterFormula")
If m_CalProfile Is Nothing Then
Exit Sub
End If
exclude(0)="A"
exclude(1)="D"
Set m_RuleDoc = m_Db.CreateDocument
Call m_RuleDoc.ReplaceItemValue("Form","Mailrule")
Call m_RuleDoc.ReplaceItemValue("action","1")
Call m_RuleDoc.ReplaceItemValue("condition","1")
Call m_RuleDoc.ReplaceItemValue("logic","1")
Call m_RuleDoc.ReplaceItemValue("Type","1")
Call m_RuleDoc.ReplaceItemValue("TokActionList","1|1|($JunkMail)")
Call m_RuleDoc.ReplaceItemValue("tokConditionList","2|1|[SPAM]|0")
Call m_RuleDoc.ReplaceItemValue("inportance","1")
Call m_RuleDoc.ReplaceItemValue("importancecond","1")
Call m_RuleDoc.ReplaceItemValue("operator","0")
Call m_RuleDoc.ReplaceItemValue("ExpireDates","D")
Call m_RuleDoc.ReplaceItemValue("ExpireNumber","5")
Call m_RuleDoc.ReplaceItemValue("ConditionList", " Subject contains [SPAM]")
Call m_RuleDoc.ReplaceItemValue("ActionList"," move to folder ($JunkMail)")
Call m_RuleDoc.ReplaceItemValue("ExcludeFromView",exclude)
Call m_RuleDoc.ReplaceItemValue("$FilterFormula","")
Call m_RuleDoc.ReplaceItemValue("$NoPurge","")
Call m_RuleDoc.ReplaceItemValue("Enable", "1")
Call m_RuleDoc.ReplaceItemValue("PROTECTFROMARCHIVE", "1")
Call m_RuleDoc.ReplaceItemValue("OrderNum",Highest)
Call m_RuleDoc.ComputeWithForm(False,False)
Dim ws As New NotesUIWorkspace
Dim uidoc As notesuidocument
Set uidoc = ws.editdocument(True,m_RuleDoc)
Call SaveRule(m_RuleDoc, uidoc)
End Sub
Script Library - Function SaveRule
Function SaveRule (m_RuleDoc As NotesDocument, m_uidoc As NotesUIDocument) As String
Set note = m_RuleDoc
Set uidoc = m_uidoc
Call ButtonOKClient()
End function