Agent creates two docs instead of one!

I’m going nuts with this problem. I have an agent that prints out a blank html form. When a user hits submit, the action goes to a processing agent which creates a Notes document out of the form. The problem is, sometimes, it runs correctly and a single document is created. Other times, two documents are created. It’s as if the script looped through twice. The button is clicked only once. The processing script only runs once. But two documents are created! I need to get this fixed. Any help would be mucho appreciated.

Thanks,

H

Subject: Agent creates two docs instead of one!!!

I don’t suppose you’d let us see the code, would you?

Subject: RE: Agent creates two docs instead of one!!!

you got it…

If create$ = “item” Then

	x% = x% + 1

	If (x% = 1) Then

		punid$ = Right(qs$, 32)

		Set pdoc = db.GetDocumentByUNID(punid$)

		Set newdoc = ParseContentRequest(doc)

		newdoc.Form = "OrderItemReceived"

		newdoc.OrderID = pdoc.OrderID(0)

		

		Dim oldcdoc As NotesDocument

		Call itemview.Refresh

		Set oldcdoc = itemview.GetDocumentByKey(pdoc.OrderID(0), True)

		

		If Not oldcdoc Is Nothing Then

			newref% = Cint(Right(oldcdoc.RefID(0), 2)) + 1

			If newref% < 10 Then

				newr$ = "0" & Cstr(newref% )

			Else

				newr$ = Cstr(newref%)

			End If

		Else

			newr$ = "01"

		End If

		

		newdoc.ItemIndex = Cint(newr$)

		newdoc.RefID = pdoc.OrderID(0) & "-" & newr$

		Call newdoc.Save (False, False)

		Call itemview.Refresh

		

		Dim dc As NotesDocumentCollection

		Set dc = itemview.GetAllDocumentsByKey(pdoc.OrderID(0))

		Call UpdateMainTotals(dc, pdoc)

		url$ = |<meta http-equiv=refresh content="1; url=agpodeditint?openagent&unid=| & punid$ & |">|

	End If

End If

I added the if(x%=1) to see if it was looping, but it had no effect. Still creates two docs. The function ParseContentRequest does not save a document at all. It just sets field values for “newdoc” and returns it unsaved.

Subject: RE: Agent creates two docs instead of one!!!

“ParseContentRequest does not save a document at all. It just sets field values for “newdoc” and returns it unsaved.”

Can we see it anyway?

Subject: RE: Agent creates two docs instead of one!!!

Function ParseContentRequest(doc As NotesDocument) As NotesDocument

'Parses content_request CGI variable for field values. Saves all field values to document.

'content request format: fieldname=value&



On Error Goto ErrHandler



Dim s As New NotesSession

Dim db As NotesDatabase



Dim fullstrings() As String

Dim fields() As String

Dim values() As String

Dim item As NotesItem

Dim ItemValues() As String

Dim backdoc As NotesDocument



Set db = s.CurrentDatabase

Set backdoc = db.CreateDocument



'Grab string to parse

SillyString$ = doc.Request_Content(0)

'Error 7777

If sillyString$="" Then

	Set parseContentRequest = backdoc

	Exit Function

End If

'parse string fragments into arrays

found% = Instr(SillyString$, "&")



i=0

Do Until found% = 0

	Redim Preserve fullstrings(i) As String

	

	fullstrings(i) = Left$(SillyString$, found% -1)

	SillyString$ = Right$(SillyString$, Len(SillyString$) - found%)

	

	i=i+1

	found% = Instr(SillyString$, "&")

Loop



'Last iteration to get the last value



Redim Preserve Fullstrings(i) As String

Fullstrings(i) = SillyString$



'Parse Array into two arrays of Field Names/Values

Redim fields(Ubound(fullstrings)) As String

Redim values(Ubound(fullstrings)) As String



For i = 0 To Ubound(fullstrings)

	found% = Instr(fullstrings(i), "=")

	'fields(i) = Left$(fullstrings(i), found% - 1) 'revescape field names to get the $ fields

	fields(i) = RevEscape(Left$(fullstrings(i), found% - 1)) 'revescape field names to get the $ fields

	If Len(fullstrings(i)) > found% Then

		values(i) = RevEscape(Right$(fullstrings(i), Len(fullstrings(i)) - found%))		

	End If

Next





'Set values into appropriate fields on backend Document

For i = 0 To Ubound(fields)

	

	If backdoc.HasItem(Fields(i)) Then 	

		

		Set Item = Backdoc.GetFirstItem(Fields(i))

		item.IsSummary = True

		

		If Instr(Values(i), ",") > 0 Then 'Multi-value Field

			

			'Split the value to many values

			found% = Instr(Values(i), ",")

			

			j=0

			Redim ItemValues(j) As String

			

			Do Until (found% = 0)

				

				Redim Preserve ItemValues(j) As String

				

				ItemValues(j) = Left$(Values(i), found% -1)

				Values(i) = Right$(Values(i), Len(Values(i)) - found%)

				

				j=j+1

				found% = Instr(Values(i), ",")

				

			Loop

			

			Forall x In ItemValues

				If Not (Item.Contains(x)) Then 

					Item.AppendToTextList x

				End If

			End Forall

			

		Else

			

			'Is this the first time we hit this field? Then replace 	Else append

			

			FoundField = False

			For j = 0 To i -1

				If fields(j) = fields(i) Then

					FoundField = True

					Exit For

				End If

			Next

			

			If FoundField = True Then  'We've hit this field aready - append the current value

				'If Not (Item.Contains(Values(i))) Then 

				Item.AppendToTextList values(i)

				'End If	

			Else 'First time with this field - replace the value

				item.Remove

				Set Item = New NotesItem(Backdoc, Fields(i), Values(i))	

				item.IsSummary = True

			End If

			

		End If

		

	Else 'Just make the new item with the value

		Set Item = New NotesItem(Backdoc, Fields(i), Values(i))	

		item.IsSummary = True

	End If	

	

	

Next



Set ParseContentRequest = backdoc

Exit Function

ErrHandler:

Print "ParseContentRequest Error: " & Err() & " on line " & Erl() & "<BR>" & Error

'Print sillystring$

'Print doc.Query_String(0)

Exit Function

End Function

Subject: RE: Agent creates two docs instead of one!!!

the odd thing about this problem is that it’s sporadic. sometimes it creates only one doc, as it should, but lately it’s been creating one doc on some occassions and two docs on others. i tested over and over to try and find a difference in the two occassions, but there is no difference. sometimes, the server feels like creating one, other times, it creates two.