Code runs twice in web browser when open for editing

I have the following code attached to a button on a form.When I use the button in a web browser and the form is opened for editing I get 2 emails.

In all other situations I get one email.

Does anyone know why this is happening?

emailtxt:= “Message body will go here”;

@MailSend(SalesRep; “”; “”;

“New Email”;

“”;

emailtxt

)

Subject: Code runs twice in web browser when open for editing

What values do you have in “SalesRep”

Subject: RE: Code runs twice in web browser when open for editing

It’s irrelevent - it’s one value if that’s what you are thinking. If I hard code a value it still sends 2 emails only when the form is open for editing. I’m thinking maybe hitting the button submits the form (saves the document) and then somehow the formula is run again a second time. I’m only hitting the button once, though.

Subject: Is there there a WebQuerySave agent?

Subject: RE: Is there there a WebQuerySave agent?

Yes. How does that matter?

Subject: Well what does the WQS agent do? Could it be sending an email?

Subject: Well what does the WQS agent do? Could it be sending an email?

OK, here’s the WQS:@Command([ToolsRunMacro]; “UnLockDoc”)

The code for that agent saves the document but doesn’t send an email:

Sub Initialize

Dim admin As String

Dim session As New notessession

Set db = session.currentdatabase	

Dim doc As notesdocument

Dim newReaders(1 To 7) As String

Dim readerItem1 As NotesItem

Dim readerItem2 As NotesItem





Set doc=session.documentcontext

Call doc.removeitem("Locked")

Call doc.removeitem("Who")



If Not(doc.ClientComments(0) = "") Then

	whenNow = Today() + " - "

	

	tc1 = doc.Clientcomments(0)

	tc2 = doc.tcomments(0)		

	tc3 = WhenNow + tc1 + 	Chr(10) + tc2

	doc.tcomments = tc3

	doc.ClientComments = ""

End If



newReaders(1) = doc.SalesRep (0)

newReaders(2) = doc.SalesManager(0)

newReaders(3) = doc.RegionalManager(0)

newReaders(4) = doc.Administrator (0)

newReaders(5) = "[QA]"

newReaders(6) = "[5]"

newReaders(7) = "[6]"



Set ReaderItem1 =  doc.ReplaceItemValue( "$READERS", newReaders )

ReaderItem1.IsReaders = True



Set ReaderItem2 =  doc.ReplaceItemValue( "MyReaders", newReaders )

ReaderItem2.IsReaders = True





Call doc.save(True, True)	

End Sub