Instructions in PostOpen event are not working properly

I have a hidden field “Sstatus” (text, editable) on a document which I need to fill up with the value of the field “status” (dialog list, editable) in the PostOpen event with this instruction:@SetField(“Sstatus”;status);

Later on, I need to check on both fields in the PostSave event to register in an audit trail each time the “Sstatus” differs from “status”.

FIELD status := status;

FIELD Audittrail := Audittrail;

FIELD AuditTextSTAT := AuditTextSTAT;

TodayStr :=@Text(@Day(@Today)) + “-” + @Text(@Month(@Today)) + “-” + @Text(@Year(@Today));

AuditTextSTAT:= AuditTrail + @NewLine + "The field Status has been changed from " + Sstatus + " to " + status + ". " + " on " + TodayStr + " by " + @Name([CN];@UserName) + “.”;

@If(status != Sstatus);

@Do(

@SetField(“AuditTrail”;AuditTextSTAT);

@PostedCommand([ViewRefreshFields])

)

Unfortunately, “Sstatus” remains blank in the PostOpen event and also the “AuditTrail” field in the document is not filled up.

Subject: If I could offer some advice…

I understand that you are trying to track changes to a field value.However, I have found that storing the original value in a field is really not the way to go. Even if your users do not make any changes to the document, they will be presented with a dialog to save changes when they close it.

Instead, I would suggest storing the original value in a global variable.

That way, you aren’t changing the document in any way, and avoiding that closing dialog if it isn’t necessary.

In the “Globals” section of the form design place a statement similar to the following in the “Declarations”:

Dim holdStatus

In the PostOpen event of the form, place the following statements (only save the field contents if the user is editing an existing document):

If Source.IsNewDoc Then Exit Sub

If Not Source.EditMode Then Exit Sub

holdStatus = Source.FieldGetText( “Status” )

You should also place similar code in the Querymodechange event (in case the user switches to edit mode after opening the document):

If not( Source.EditMode ) Then holdStatus = Source.FieldGetText( “Status” )

Finally, in the QuerySave event, you can compare the value of the field with that of the global variable, and audit any changes. Something like…

If Source.IsNewDoc Then Exit Sub

Dim session As New NotesSession

Dim thisDoc As NotesDocument

Set thisDoc = Source.Document

If thisDoc.Status(0) <> holdStatus Then

thisDoc.AuditTextSTAT = thisDoc.AuditTextSTAT(0) & Chr$(10) & |The field Status has been changed from "| &_

Format$( holdStatus ) & |" to “| & thisDoc.Status(0) & |” on | + Format$( Today, “dd/MMM/yyyy” ) & " by " &_

session.CommonUserName & “.”

End If

Hope that helps!

T.

Subject: RE: If I could offer some advice…

I cannot try this out right now, but I’ll let you know as soon as I test your suggested changes.Thanks a lot for yr help, already!