Email alerts-agent/lotuscript assistance

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

Subject: email alerts-agent/lotuscript assistance

You are only reading the first value of the field:doc_Alert.FMTYPE(0)

If it is a multi value field, you need to loop through all the elements in the array.

Subject: RE: email alerts-agent/lotuscript assistance

Karl-Henry thank you for your response. This section of the code doesn’t do the looping? (The checkbox field options (multiple values) have aliases and in the code I’m using the aliases in the If statements.)

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 = “
Topic A
” + “=======================================

subject21_Main_gr = subject21_Main_gr + doc_Alert.All_Attch(0) + “

docSubjectGR = doc_Alert.Statement(0)

'Topic B

ElseIf doc_Alert.FMTYPE(0) = “2” Then

subject22_Title_gr = “
Topic B
” + “=======================================

subject22_Main_gr = subject22_Main_gr + doc_Alert.All_Attch(0) + “

docSubjectGR = doc_Alert.Statement(0)

'Multiple Topics

ElseIf doc_Alert.FMTYPE(0) = “1” And doc_Alert.FMTYPE(0) = “2” Then

multcat1_Title_gr = “
Multiple Topics
” + “=========================================

multcat1_Main_gr = multcat1_Main_gr + doc_Alert.All_Attch(0) + “

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

Thanks.

Subject: It doesn’t loop on the multipkle selection no.

Step through your code in debugger, you’ll be able to see why it doesn’t work.

Subject: RE: email alerts-agent/lotuscript assistance

No, you are not looping through the values in the multi-value field, you are just checking the first element of the array.

One workaround (if each option is unique) could be something like this:

If Instr(Join(doc_Alert.GetItemValue(“FMTYPE”)),“1”)>0 Then

I would recommend using the GetItemValue method instead of using extended notation.