Getdocumentbykey, username, and field population

I cannot figure out why this script is not working!It is an action button in the action bar.

I have already used the Use “scriptlibrary” in the options section of the form and the action.

If anyone has an idea, please let me know.

Here is the actual script:

Sub Click(Source As Button)

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim db As New NotesDatabase("","")

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim doc2 As NotesDocument

Dim rtitem As Variant

Dim ContactDoc As NotesDocument

Dim userName As New NotesName(session.UserName)



Set db = session.CurrentDatabase

Set uidoc = workspace.CurrentDocument

Set doc = uidoc.Document

Set view = db.GetView( "Lookup" )

Set doc2 = view.GetDocumentByKey(userName)



Call GetContactDoc(ContactDoc)

If Not (ContactDoc Is Nothing) Then

	

	Call workspace.SetTargetFrame("")		

	Set uidoc = workspace.CurrentDocument

	Set doc = uidoc.Document

	

	doc2.ReqPhone=doc.Phone

	doc2.ReqAdd=doc.Address

	

	Call uidoc.GoToField( "Amount" )

	Call uidoc.refresh

	

Else

	Msgbox "You must first complete an Contact Information before you can request and peripherals from another office. Return to the main menu, navigate to the 'Contacts by Office' view,  and click the 'Create New Contact' burron to create a user profile.",64,"Contact Information Profile Missing"

End If	

End Sub

Subject: Getdocumentbykey, username, and field population

GetDocumentByKey takes a string as a parameter. You are passing in a NotesName object. Try this instead…

Set doc2 = view.GetDocumentByKey(session.UserName)

That should work provided your look up view is sorted by the Canonicalized name.