Append a txt field to an email

Not sure how to put this but here goes…How do you append a txt field in a document to an email. I would like to have an email sent when the field in the document is changed and to show the changes in the email. to the recpt. Such as if the document field that contains a type of candy and it is change from one type to another it would send an email showing what it was and what it is now.

Thanks in advance

Subject: Append a txt field to an email

Let me restate to confirm I understand the question.

In Application X, a form has a field. When the value in the field is changed, you want an email sent to <some person/group> with the details.

If I have that right, you have a couple of options.

  1. Roll your own. You can use the field OnChange event to detect and respond to changes. (I think it’s the OnChange, it could be onBlur and you can also use the Entering and Exiting events together). This works, Notes designer help has examples you can use, and you can be as flexible as you want.

  2. Let someone else do the work. Go to OpenNTF.org, get ‘Audit Manager’, set it up and you have a fully functional AWESOME audit trail system that includes sending email alerts. It’s worth the download. It is, in fact, about the best app I’ve ever used. Even if you don’t need audit trails, it is amazingly helpful in debugging app problems because you can see who changed what fields when and figure out when your code goofed up.

Subject: RE: Append a txt field to an email

That is correct. I am using OnChange and it does send an email when the field changes. I just can not come up with the code to add the information from that field that has changed to the body of the email so the person knows what changed from and to.And I will take a look at OpenNTF.org, get ‘Audit Manager’.

But right now I would to get this to work.

thanks

Subject: Found some code

I have done this before and can’t find my code. The basic concept isEnter the field and grab the value.

OnChange or on exit, compare the initial and final and build your email message if the value is different.

If I can find the code I’ll post it.

But seriously, Audit Manager just takes care of it for you. You need to add a dll to the server and update the server’s ini file but once that’s done, the audit happens at the server level so user’s can’t bypass the code. It’s freaking sweet and should be part of the Domino core functionality.

This is wicked old (from '97 actually) but it works. I think the onChange may provide an easier way to manage this but I just can’t find an example yet.

I found this in the Notes User Discussion website (credit to Kevin Loftis);

In the (Declarations) event of the field:

Dim tPreviousValue As String

In the Entering event:

tPreviousValue = nUIDoc.FieldGetText ( “YourFieldName” )

In the Exiting event:

Dim tCurrentValue As String

tCurrentValue = nUIDoc.FieldGetText( “YourFieldName” )

If Trim$( tPreviousValue ) <> Trim$( tCurrentValue ) Then

Do your stuff

End If

<edit 2>

OK, I found my ‘onChange’ code and it will work for your needs. Note that the field’s initial value is trapped by the form’s QueryOpen event. The code below is used to revert the field to the original value if a reason for the change isn’t entered by the user but you can adapt this to send an email with the ‘from/to’ values.

Enjoy!

Sub Onchange(Source As Field)

'initReminderDate set by form QueryOpen event

Dim s As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim newDueDate As String	

Dim Reason As String

Dim CRLF As String



CRLF = Chr(13) & Chr(10)



Set uidoc = workspace.CurrentDocument

newDueDate = Cstr(uidoc.FieldGetText("VerifyReminderDueDate"))



If initReminderDate <> ""  Then

	Reason = Inputbox$ ( "Please enter a justification for extending the verification completion date." , "Justification?"  )

	If Reason = "" Then 

		Messagebox "Sorry, you must enter a reason, reminder date is reverted to: " & initReminderDate

		Call uiDoc.FieldSetText("VerifyReminderDueDate", initReminderDate)

		Call uiDoc.Refresh

		Exit Sub

	Elseif Reason <> "" Then

		If uidoc.FieldGetText("VerificationExtensionJustify") = "" Then

			Call uidoc.FieldAppendText("VerificationExtensionJustify", "[Extension granted on: " & Cstr(Now) & _

			" by: " & s.CommonUserName & ": " & Reason & "] ")

		Else

			Call uidoc.FieldAppendText("VerificationExtensionJustify",".  " & CRLF & "[Extension granted on: " & Cstr(Now) & _

			" by: " & s.CommonUserName & ": " & Reason & "] ")

		End If

	Else 

		'do nothing - it's the initial setting of the due date so no reason is required.

	End If

End If

End Sub

Subject: RE: Found some code

Thank you that worked very well

Subject: Glad to help, sorry it took so long to find the code