Error with session.CommonUserName

Recently we upgraded our Notes environment from R5 to R7 and running to an issue with one of my workflow database. I have an ‘Author’ field which captures users names, date and time. The field stop working for users who’s Clients has been upgraded to R7.

I’m using the following code in the Terminate Event of the “Author” field. It fails to append the user’s name.

Sub Terminate

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim uidoc As NotesUIDocument

Set uidoc = workspace.CurrentDocument



Author = uidoc.FieldGetText("Author")

RevApproval_a = uidoc.FieldGetText ("RevApproval")

If Author = "" Then     

If RevApproval_a <> “” Then

		Author = "Completed by " & session.CommonUserName & " on " & Format(Now(), "Long Date") 

		Call uidoc.FieldSetText("Author", Author)

		Call uidoc.save

	End If

End If

End Sub

I appreciate any help you can provide.

TIA!

-tb

Subject: Error with session.CommonUserName

I would agree with Dmytro, I would assume since you’re in the termination event you shuold be working with the document in the backend.

Fairly simple just change you code to (but I made a few assuming - like Author is a single value)

Sub Terminate

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim doc As NotesDocument

Set doc = workspace.CurrentDocument.Document



Author = doc.Author(0)

RevApproval_a = doc.RevApproval(0)

If Author = "" Then

If RevApproval_a <> “” Then

		Author = "Completed by " & session.CommonUserName & " on " & Format(Now(), "Long Date") 

		doc.Author =  Author

		Call doc.save(False,False,False)

	End If

End If

End Sub

Subject: Error with session.CommonUserName

your subject states: Error with session.CommonUserName

what is the error?

Subject: Error with session.CommonUserName

probably in 7 version, when document go to terminate event, it change mode to readable, that’s why Call uidoc.FieldSetText(“Author”, Author)

Call uidoc.save

have gave errors

Dim workspace As New NotesUIWorkspace

Dim session As New NotesSession

Dim uidoc As NotesUIDocument

Dim doc As notesdocument

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.document

Author = uidoc.FieldGetText("Author")

RevApproval_a = uidoc.FieldGetText ("RevApproval")



If Author = "" Then

	

	If RevApproval_a <> "" Then

		Author = "Completed by " & session.CommonUserName & " on " & Format(Now(), "Long Date")

		Call doc.ReplaceItemValue("Author", Author)

’ Call uidoc.FieldSetText(“Author”, Author)

		Call doc.Save(True, True)

’ Call uidoc.save()

		Print "after save=" & Author

	End If

Subject: RE: Error with session.CommonUserName

Thanks, everyone! I used the suggested code and the field populates the user’s name now.

Thanks again!

  • tb

Subject: RE: Error with session.CommonUserName

Hey guys, Sorry I spoke too soon.

It appears that the new code is appending wrong name in the field. Anyone who tries to edit the field (even if they’re not allowed to edit the field), their name appears as if they approved the request. Can someone please help me to modify the code so that the only the name that appears in the field would be the person’s who edit & save the field?

Thank you in advance for your help!