AppendDocLink Issue

Hello, I am trying to on a QuerySave event look if a field is set to absent. If so send an email with a doc link otherwise nothing.

Below is my code. However even if the field is set to Absent it skips to the end as if it weren’t true. Any Ideas?

Process = uidoc.FieldGetText("Process")

If  Process = “Absent”  Then

	Dim email As NotesDocument 

	Dim rti As NotesRichTextItem 

	Dim nam As NotesName 

	

' create pointer to current document to get field values

	Set uidoc = wspace.CurrentDocument

' define TER's owner, approving managers, & status 

	Employee = uidoc.FieldGetText ("Employee")

	

	

' create name object for HR owner (Person)

	Set nam = session.CreateName (Employee)

' create common name for TER owner

	pers = nam.Common 

	

	

' get the database

	Set db = session.CurrentDatabase 

' create a new email document in the database

	Set email = New NotesDocument (db)

	

' create the Subject line of the email

	email.Subject = pers + " has a Time & Expense Report for you to review and approve!"

	

' create the Rich Text item to place in the body of the email

	Set rti = New NotesRichTextItem( email, "Body" )

	

' create the email's body

	Call rti.AddNewline (1)	

	Call rti.AppendText ("Please review " + pers + "'s TER for Weeks " + week + " & " + _

	week1 + ".")	

	Call rti.AddNewline (3)	

	Call rti.AppendText ("You can open the Time & Expense Report in question by " + _

	"clicking on the Document Link below.  If the link does not open immediately, " + _

	"please try again later ... ")

	Call rti.AddNewline (2)

	Call rti.AppendText ("Double-click this ==> ")

	

' create the doc link (doc is the document to link the RTI to & db.Title shows 

' the link's database title when you put your mouse over it)

	Set doc = uidoc.Document 

	Call rti.AppendDocLink (doc,db.Title )

	

' mail the new document

	Call email.Send( False, doc.suprvisor)

	

End If

End Sub

Subject: AppendDocLink Issue

Have you used the debugger to see what the actual value of Process (the variable) is?

Subject: RE: AppendDocLink Issue

Yes. The value is “Absent” I have also tried If Process <> “Absent” Then

…

It runs then, but if the value is something else it runs too :slight_smile:

Subject: RE: AppendDocLink Issue

You’re sure there are no extra spaces or anything? The field value isn’t "Absent " or some such? Try this check:

If Instr(LCase(Process),“absent”) Then

Subject: RE: AppendDocLink Issue

Your problem is that you forgot to use Option Declare. That would have revealed that your quotes are not quotes.

Subject: RE: AppendDocLink Issue

I was able to just Dim the process var as a string and it worked. As much as I would like to clean up the original developers code :slight_smile:

Thanks for your help

Subject: *Do it now at your leisure, or later in haste when there is a problem.

Subject: RE: AppendDocLink Issue

I have a major issue. I am modifying existing code. The original developer used on Option Public. I get errors when trying to use Option Declare. Replacing public with declare will i have to rewrite all of the code? Sorry I am still new at this?

Thanks

Subject: RE: AppendDocLink Issue

You won’t have to rewrite all the code, but you will have to go clean up what the original developer did not, which is undeclared variables, for example. Don’t worry, it will be worth the effort, as this will reduce this sort of issue considerably.

Subject: RE: AppendDocLink Issue

I will slowly work on declaring the variable in my local copy. I will have to determine on alot of them what type but most are string.

Thanks Again