developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum

developerWorks




email alerts-agent/lotuscript assistance
fatsoua fatsoua 10/20/2014 06:19 AM
General All Releases All Platforms


I have created a form where the content manager can create a document relevant to a single or multiple topics (selection through check-box) and send it (via agent-email alert) to subscribed users (of that/those topics). The agent I have created works only with single choice topics, if the content manager chooses 2 or more topics, the agent recognizes only the first one. What am I doing wrong in the agent-script? Thanks in advance. Here's my agent:
Option Public
Sub Initialize
' Declarations
Dim db As NotesDatabase
Dim session As New NotesSession

' Instantiations
Set db = session.CurrentDatabase

Dim doc_Select_Users_for_Alert As NotesDocument
Dim view_Select_Users_for_Alert As NotesView
Dim doc_Alert As NotesDocument
Dim view_Alert As NotesView
Dim docType_gr As String

' Email Alert
Dim IntroductoryText_gr As String
Dim MainText_gr As String
Dim EndingText_gr As String

Parameter_Server = "intraweb01/gov"

Set view_Alert = db.GetView("xxx_alert")
Set doc_Alert = view_Alert.GetFirstDocument

If doc_Alert Is Nothing Then Exit Sub

IntroductoryText_gr = "Intro text ...:<br>"
EndingText_gr = "Ending text ..."

' Topic A
Dim subject21_gr As String
Dim subject21_Title_gr As String
Dim subject21_Main_gr As String

' Topic B
Dim subject22_gr As String
Dim subject22_Title_gr As String
Dim subject22_Main_gr As String

' Multiple Topics
Dim multcat1_gr As String
Dim multcat1_Title_gr As String
Dim multcat1_Main_gr As String

Server_AddressD="http://www.xxx.cy/xxx.nsf/"
Server_AddressP="http://www.xxx.cy"

Do Until doc_Alert Is Nothing

If doc_Alert.Form(0) = "xxx_new_el" Then

If doc_Alert.FMTYPE(0)="" Then
'do nothing

' Topic A
ElseIf doc_Alert.FMTYPE(0) = "1" Then
subject21_Title_gr = "<br><b>Topic A</b><br>" + "=======================================<br>"
subject21_Main_gr = subject21_Main_gr + doc_Alert.All_Attch(0) + "<br><br>"
docSubjectGR = doc_Alert.Statement(0)

'Topic B
ElseIf doc_Alert.FMTYPE(0) = "2" Then
subject22_Title_gr = "<br><b>Topic B</b><br>" + "=======================================<br>"
subject22_Main_gr = subject22_Main_gr + doc_Alert.All_Attch(0) + "<br><br>"
docSubjectGR = doc_Alert.Statement(0)

'Multiple Topics
ElseIf doc_Alert.FMTYPE(0) = "1" And doc_Alert.FMTYPE(0) = "2" Then
multcat1_Title_gr = "<br><b>Multiple Topics</b><br>" + "=========================================<br>"
multcat1_Main_gr = multcat1_Main_gr + doc_Alert.All_Attch(0) + "<br><br>"
docSubjectGR = doc_Alert.Statement(0)
End If

End If

doc_Alert.SentAlert = "1"
Call doc_Alert.Save(True,False)
Set doc_Alert = view_Alert.GetFirstDocument

On Error Resume Next

Loop

subject21_gr = subject21_Title_gr + subject21_Main_gr
subject22_gr = subject22_Title_gr + subject22_Main_gr
multcat1_gr = multcat1_Title_gr + multcat1_Main_gr

Dim yCounter As Integer

yCounter = 0

' Εmail Parameters
Dim docMail As NotesDocument
Dim Language As String
Dim docMailBody_A As String
Dim docMailBody_B As String
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream

Set view_Select_Users_for_Alert = db.GetView("Users for Alerts by email")

Set doc_Select_Users_for_Alert = view_Select_Users_for_Alert.GetFirstDocument

Do Until doc_Select_Users_for_Alert Is Nothing

If doc_Select_Users_for_Alert.Form(0) = "xxx_el" Then
Language = "GR"
End If

If Language = "GR" Then
docMailBody_A = IntroductoryText_gr
End If

' Θέματα
For yCounter = 0 To UBound(doc_Select_Users_for_Alert.TopicsB)

' Topic A
If doc_Select_Users_for_Alert.TopicsB(yCounter) = "1" And Language = "GR" Then
If subject21_gr <> "" Then
docMailBody_B = docMailBody_B + subject21_gr
End If
End If

' Topic B
If doc_Select_Users_for_Alert.TopicsB(yCounter) = "2" And Language = "GR" Then
If subject22_gr <> "" Then
docMailBody_B = docMailBody_B + subject22_gr
End If
End If

' Multiple Topics
If doc_Select_Users_for_Alert.TopicsB(yCounter) = "1" And doc_Select_Users_for_Alert.TopicsB(yCounter) = "2" And Language = "GR" Then
If multcat1_gr <> "" Then
docMailBody_B = docMailBody_B + multcat1_gr
End If
End If

Next yCounter

If Language = "GR" Then

If docMailBody_B <> "" Then
Set stream = session.CreateStream
Set docMail = New NotesDocument(db)
Set body = docMail.CreateMIMEEntity
docMail.Form = "Memo"
docMail.Principal = "XXX"
docMail.Subject = "XXX - email Alert: " + docSubjectGR

session.ConvertMIME = False ' Do not convert MIME to rich text
Call stream.WriteText(docMailBody_A + Chr(13) + Chr(13) + docMailBody_B + Chr(13) + Chr(13) + EndingText_gr)
Call body.SetContentFromText _
(stream, "text/html;charset=UTF-8", ENC_NONE)
Call docMail.Send(False, doc_Select_Users_for_Alert.alert_email(0))
session.ConvertMIME = True ' Restore conversion
docMailBody_B = ""
End If

End If

Set doc_Select_Users_for_Alert = view_Select_Users_for_Alert.GetNextDocument(doc_Select_Users_for_Alert)

On Error Resume Next

Loop

session.ConvertMIME = True ' Restore conversion

End Sub

Go back