LS Agent with mailsend and doc link opens with wrong form?

Hi there

I love this forum!

Okay, I have this agent that works okey doke. Problem is that the doclink generated opens with the wrong form.

The form to open with is SWATImport - and instead it is using another form. I have the SWATImport even set as the default db form.

Here is the agent…any ideas why?

Sub Initialize

'The purpose of V2V agent is to pull all unprocessed customer records from the V2V database, SWAT have an 'Attack' or 'Defend' 

  'situation associated with them, and create a record in the SWAT Scorecard databse.

Dim session As New NotesSession

Dim SWATdb As notesdatabase

Dim V2Vdb As notesdatabase

Dim V2Vdoc As notesdocument

Dim collection As NotesDocumentCollection

Dim SWATdoc As NotesDocument

Dim BUdoc As NotesDocument

Dim BUView As NotesView

Dim Configview As NotesView

Dim Configdoc As NotesDocument







Set V2Vdb = session.currentdatabase

Set BUview = V2Vdb.getview("buInfo")



'Retrieving the name and location of the SWAT DB

Set Configview = V2Vdb.GetView("Config")

Set Configdoc = Configview.GetFirstDocument

Servername = Configdoc.servername

DBName = Configdoc.DBName

'Get the SWAT database instance

'Set SWATdb = session.GetDatabase("", "PL and SWAT combined.nsf")

Set SWATdb = session.GetDatabase(Servername, DBName)

'If we can’t find the SWAT DB exit the whole agent

If Not SWATdb.IsOpen Then

	Print "The V2V Push to SWAT agent could not find SWAT DB"

	Exit Sub

End If







'V2V is the formula used to find documents in V2V SWAT need to be procesed (have SWAT documents created).

searchFormula$ = {Form = "V2VCall" & ProcesstoSWAT= "No" & (CompAttack = "Yes" |  CompDefend = "Yes")}



'V2V is the collection of document found SWAT match the criteria in the searchFormula

Set collection = V2Vdb.Search(searchFormula$, Nothing,0)

Set V2Vdoc = collection.GetFirstDocument()



While Not(V2Vdoc Is Nothing)

	'Collect all the info needed to create the SWAT document

	DBNumber = V2Vdoc.DBNumber

	CustomerName = V2Vdoc.customername

	Region = V2Vdoc.region

	BusinessUnit = V2Vdoc.businessunit

	AccountHealth = V2Vdoc.accounthealth

	SalesRep = V2Vdoc.salesrep

	BPName = V2Vdoc.PartnerName

	NotesSeats = V2Vdoc.NumNotesUsers

	DominoServers = V2Vdoc.NumDominoServers

	Siebel = V2Vdoc.SiebelNo

	Attack = V2Vdoc.CompAttack

	TypeAttack = V2Vdoc.TypeOFAttack

	TypeAttackPlay = V2Vdoc.AttackPlay

	AddHelp = V2Vdoc.Attack_additional_Help

	Defend = V2Vdoc.CompDefend

	TypeDefend = V2Vdoc.TypeOFDefend

	DefendType = V2Vdoc.DefendType

	

	'Ready to create the document in the SWAT DB

	Set SWATdoc = SWATdb.CreateDocument

	SWATdoc.form = "SwatImport"

	SWATdoc.status = "New Record"

	

	'Set the fields on the SWAT record

	SWATdoc.DBNumber = DBNumber

	SWATdoc.CustomerName = CustomerName

	SWATdoc.Region = Region

	SWATdoc.BusinessUnit = BusinessUnit

	SWATdoc.AccountHealth = AccountHealth

	SWATdoc.SalesRep = Salesrep

	SWATdoc.BPName = BPName

	SWATdoc.NumNotesSeats = NotesUsers

	SWATdoc.NumDominoServers =  DominoServers

	SWATdoc.SiebelNo = Siebel

	SWATdoc.CompAttack = Attack

	SWATdoc.TypeOFAttack = TypeAttack

	SWATdoc.TypeAttackPlay = AttackPlay

	SWATdoc.Attack_additional_Help = AddHelp

	SWATdoc.Defend = Defend

	SWATdoc.TypeDefend = TypeDefend

	SWATdoc.DefendType = DefendType

	

	

	'Send mail notification

	'Getting the BU document containing the appropriate email recipients ,based on the regiona and business unit

	Dim key (0 To 1)

	key(0) = Region(0)

	key (1) = BusinessUnit(0)

	

	'Setting up to retrieve the recipients

	Dim dc As notesdocumentcollection

	Set dc = buview.GetAllDocumentsByKey(key, True)

	Set BUdoc = dc.GetFirstDocument()

	'Figuring out if this attack or defend and choosing recipients based on that

	Dim sendto( 1 To 4 ) As String

	If TypeAttack(0) = "Collaboration" Or DefendType(0) = "Collaboration"  Then

		sendto(1) = BUdoc.CollabSalesLeader(0)

		copyto = BUdoc.CollabSWATFocal

	Elseif  TypeAttack(0) = "Both" Or TypeDefend(0) = "Both" Then

		sendto( 1 ) = BUdoc.PortalSalesLeader(0)

		sendto( 2 ) = BUdoc.CollabSalesLeader(0)

		sendto( 3 ) = BUdoc.PortalSWATFocal(0)

		sendto( 4 ) = BUdoc.CollabSWATFocal(0)

	Else

		sendto(1) = BUdoc.PortalSalesLeader(0)

		copyto = BUdoc.PortalSWATFocal 

	End If

	

	'Creating the maildocument

	Set maildoc = V2Vdb.CreateDocument

	Set body = New notesrichtextitem(maildoc,"Body")

	Set rts1 = session.CreateRichTextStyle

	Set rts2 =  session.CreateRichTextStyle

	

	rts1.FontSize = 10

	rts1.Bold = True

	rts1.NotesColor = COLOR_BLUE

	rts1.Underline = True

	

	rts2.FontSize = 8

	rts2.Bold = False

	rts2.NotesColor = COLOR_BLACK

	rts2.Underline = False

	

	

	maildoc.form = "Memo"

	maildoc.subject = "New Attack/Defend has been created in V2V and SWAT Scorecard" 

	maildoc.sendto = sendto

	maildoc.copyto = copyto

	Call body.addnewline(2)

	Call body.AppendStyle(rts1)

	Call body.AppendText("Please review the new document and complete any required fields.")

	Call body.AppendStyle(rts2)

	Call body.AddNewline(2)

	Call body.AppendStyle(rts1)

	

	Call body.AppendDocLink( SWATdoc, "Link to Document" )

	'Call body.AppendDocLink( doc,  "Link to Document:  ")

	Call maildoc.send(True)

	

	

	'Save the new record in the SWAT DB

	SWATdoc.SaveFlag = "1"

	Call SWATdoc.save(1,1)		

	

	'Save a processed update to the V2V document

	V2Vdoc.ProcesstoSWAT =  "Yes"	

	Call V2Vdoc.Save( True, False )

	

	Set V2Vdoc = collection.GetNextDocument(V2Vdoc)

Wend



On Error Goto errhandler









End

errhandler:

Messagebox "There has been an error on line " & Cstr(Erl) & ".   Please contact the database administrator"

Messagebox Err() & Error()

End Sub

Subject: LS Agent with mailsend and doc link opens with wrong form?

I’m fishing, but since it looks like you’ve set the Form attribute correctly, your problem probably is coming from the fact that you haven’t saved the backend SWATdoc when you create the link. I suggest that you move the save statement up 2 lines, so that it looks like this

'Save the new record in the SWAT DB

SWATdoc.SaveFlag = “1”

Call SWATdoc.save(1,1) 'Save a processed update to the V2V document

Call body.AppendStyle(rts1)

Call body.AppendDocLink( SWATdoc, “Link to Document” )

Call maildoc.send(True)

Subject: RE: LS Agent with mailsend and doc link opens with wrong form?

I will try that - thanks for the tip!