Sending notification using lotusscript

Hello,

In this particular agent, the goal is to send a notification when there is a request. Currently, the agent sends the notification to a primary user specified in profile database.

I have added an additional recipient based on the user that filled out the request. This recipient will receive a similar notification, but the difference is that I would like for the response button to the request to be removed/hidden for the secondary recipient.

I am having trouble modifying the output to omit respbuttons. I have tried multiple agents, multiple objects, and multiple MIMEEntity. I am unable to prompt the second agent/object/etc to generate an output. Please advice whether this approach is sound, or if there is another method that I should be doing.

Thank you very much for your time.

Function MailNotification ()

Dim mime As NotesMimeEntity

Dim html As NotesStream

Dim session As New NotesSession

Dim doc As NotesDocument

Dim EmailText1 As String, EmailText2 As String, RespButtons As String	

Dim Desc As Variant, path As String, db As NotesDatabase

Dim rightEndHTML As String, leftTableHTML As String, leftTableHTML2 As String, rightEndHTML2 As String

Dim profileDoc As NotesDocument, reqnumber As String

Dim agentLog As New NotesLog("Agent log")

Dim item As NotesItem, nam As NotesName

Dim objAttchmnt As NotesEmbeddedObject, varAttNames As Variant, attachfilework As String

Dim attach As String

Dim ReqType As String

Set doc = session.DocumentContext

Set db = session.CurrentDatabase

path = db.filepath

Set profileDoc = db.GetProfileDocument("DatabaseProfile")



If profileDoc Is Nothing Then

	doc.subject = "Problem with profile document - domino coding error"

	doc.send False, "Domino Administrator/MTLO"

	Exit Function		

End If



reqnumber = GenerateSequentialNumber( "CusHSRev" )

doc.RequestNumber  = reqnumber 

ReqType = doc.ReqType(0)



leftTableHTML = {<tr valign="top"><td bgcolor="#EEEEEE" width="144">}

rightEndHTML =  {</td></tr>}+ Chr(10) + Chr(13) 



Set nam = session.CreateName( Doc.SendTo(0)  )



EmailText1 = {<table border="0" cellspacing="2" cellpadding="0">}

EmailText1 = EmailText1 + {<tr valign="top"> <th colspan="2" align="center" bgcolor="#C0C0C0"> Customer HS Review </th></tr>}

EmailText1 =	EmailText1 + leftTableHTML + {Send To:</td><td width="240">} & nam.Common & rightEndHTML+ Chr(10) + Chr(13)

EmailText1 =	EmailText1 + leftTableHTML + {Author:</td><td width="240">} & Doc.DisplayAuthor(0) & rightEndHTML

EmailText1 =	EmailText1 + leftTableHTML + {Division:</td><td width="240">} & Doc.Division(0) & rightEndHTML+ Chr(10) + Chr(13)

EmailText1 =	EmailText1 + leftTableHTML + {Date Created:</td><td width="240">} & Doc.DateCreated(0) & {</td></tr>}	+ Chr(10) + Chr(13)

EmailText1 =	EmailText1 + leftTableHTML + {Request #:</td><td width="240">} & Doc.RequestNumber(0) & {</td></tr></table>} + Chr(10) + Chr(13)

EmailText1 =	EmailText1 + {<p>                                                                                                 </p>}		



Set desc = doc.GetFirstItem("Desc")

doc.RequestorComments = doc.Desc



leftTableHTML2 = {<tr valign="top"><td width="150" bgcolor="#EEEEEE">}

rightEndHTML2 =  {</td></tr>}+ Chr(10) + Chr(13) 



EmailText2 = {<table border="0" cellspacing="2" cellpadding="0">}

EmailText2 = EmailText2 + leftTableHTML2 + {Order Number:</td><td width="250">} & Doc.OrderNo(0) & rightEndHTML2

EmailText2 = EmailText2 + leftTableHTML2 + {Additional Order No.1:</td><td width="250">} & Doc.AddOrd1(0) & rightEndHTML2

EmailText2 = EmailText2 + leftTableHTML2 + {Additional Order No.2:</td><td width="250">} & Doc.AddOrd2(0) & rightEndHTML2

EmailText2 =	EmailText2 + leftTableHTML2 + {Additional Comments:</td><td width="250">} & Desc.GetFormattedText(False,0) & {</td></tr></table>} + Chr(10) + Chr(13)



RespButtons = Chr(10) + Chr(13) + {<br><br><table border="0" cellspacing="0" cellpadding="0">}

RespButtons = RespButtons + {<tr valign="top">}

RespButtons = RespButtons + {<td width="120"><a href="http://domsvr/} + path  + {/AllByUnid/} + doc.UniversalID + {?editdocument&newStatus=Response&login&unid=} +doc.UniversalID + {"> Response </a></td>}+ Chr(10) + Chr(13) 

RespButtons = RespButtons + {</table><br>}



attachfilework = {<a href="http://domsvr/} + path  + {/0/} + doc.UniversalID + {/$file/} 

varAttNames = Evaluate({@AttachmentNames}, doc)

If Isarray(varAttNames) Then 

	Forall attName In varAttNames 

		Set objAttchmnt = doc.GetAttachment(attName)

		If Not(objAttchmnt Is Nothing) Then 

			attach = attach + attachfilework + attName +  {">Click to launch: } + attName + {</a><br>}+ Chr(10) + Chr(13) 

		End If

	End Forall

Else 

End If		



Set html = session.CreateStream 

html.WriteText EmailText1+ EmailText2 + RespButtons + attach



Set mime = doc.CreateMIMEEntity("Body")

mime.SetContentFromText html, "text/html", ENC_NONE



If profileDoc Is Nothing Then

	doc.subject = "Problem with profile document - domino coding error"

	doc.send False, "Domino Administrator/MTLO"

Else

	Set item = profileDoc.GetFirstItem("InitialDistribution")

	Forall people In item.Values

	End Forall

	Call doc.Send(False, profileDoc.Initialdistribution) 

            Call doc.Send(False, doc.Manager) 



    End If	



doc.NewSeqNum = "Y"

doc.Year1 = Left(reqnumber,4) 

doc.Counter1 = Right(reqnumber,4)	

MailNotification = True

End Function

Subject: Sending notification using lotusscript

I would move the code that creates and sends the email to a separate subroutine, with the code that adds in the RespButtons controlled by a true/false flag that you pass as a parameter. Then call the subroutine with the flag set or not depending on who should see the buttons e.g. testing the particular recipient value inside your forall loop and calling the subroutine with true/false as appropriate

Subject: RE: Sending notification using lotusscript

I think I understand, but I’m not sure how i reference the flag as a parameter in another object.

How different is this from just adding an If.then.else to the forall?

Thank you for your time.

Subject: RE: Sending notification using lotusscript

Scarlet suggests that you pass the flag as an argument to the subroutine/function.

Surely you know how subroutines/functions work? We are talking programming 101 here…

Subject: RE: Sending notification using lotusscript

Yes. I don’t know why I didn’t understand it the first time. I apologize.

I have currently made the mailnotification function as suggested. I’m calling the function in subroutine initialize, but the loops I am trying to run does not run the function more than once, even if it’s just a for loop (for i=1 to 2…, to call the function twice) with recipients set as constants.

The problem is probably with the mailnotification function, but I don’t know what could be causing the issue.

Thank you for your time.