Variant does not contain an Object!

Hi all,

I am having problems extracting the Common Name from a Hierarchical name.

I am using the following code to extract the Common Name from doc1.

Dim doc1 As NotesDocument

homeserver = doc1.GetItemValue(“mailserver”)

servername = homeserver.Abbreviated '<— Got Error 183 Variant does not contain an object in line: 49

Print “ServerName” & servername(0) '<-- Got Error 184 Variant does not contain a container in line: 51

Set destdb = session.GetDatabase( servername(0) , mailfile(0))

Should I be assigning Dimensions to…?

homeserver

servername

I have tried a number of Dimensions but still cannot manage to return the Common Name.

Please help !!

Subject: Have you thought about this?

To display only the common name portion of names, use the [CN] parameters with @Name.

For example, in an editable names field called Members use this formula as the default value:

@Name([CN];Members)

Subject: Variant does not contain an Object !!

cmp. designer help Notes Name class

Dim homeserver As New NotesName ( doc1.GetItemValue(“mailserver”))

servername = homeserver.abbreviated

axel

Subject: Got Error 13 Type mismatch in line: 47

Hi Axel,

This give an error : Got Error 13 Type mismatch in line: 47

Dim homeserver As New NotesName ( doc1.GetItemValue(“mailserver”))


The Whole code is below…You will see ‘***Error’ on right as scrolling Half way down.


Sub Initialize

On Error Goto errhandler



Dim session As New NotesSession

Dim db As NotesDatabase		

Dim doc As NotesDocument

Dim doc1 As NotesDocument

Dim doc2 As NotesDocument

Dim agent As NotesAgent

Dim item As NotesItem

Dim nab As NotesDatabase

Dim view As NotesView		

Dim mailfile As Variant

Dim destdb As notesdatabase



Set agent = session.CurrentAgent

Set db = session.CurrentDatabase

'Get document used for passing data

Print "Oil Secretaries Calendar Agent Running Activated" 

Print "Attempting to Locate Calendar Entry being Saved..."

Set doc = db.GetDocumentByID(agent.ParameterDocID)

If doc.HasItem("Form") Then

	Print "Calendar Entry Found"

Else

	Print "Calendar Entry NOT found"	

End If

'Run Loop through any names in AlarmDialog Field

Forall n In doc.AlarmDialog

'Get current NAB

	Set nab = session.GetDatabase("" , "names.nsf")

'Get view in NAB

	Set view = nab.GetView("($Users)")

'Find person document in view

	Print "Attempting to Locate Person Document in NAB..."

	Set doc1 = view.GetDocumentByKey( n, True)

	

	If doc1.HasItem("mailserver") Then

		Print "Person Document Found"

	Else

		Print "Person Document NOT found"	

	End If

'Find MailServer field values from Person document

	Print "Extracting MailServer from Person Document"		

	Dim homeserver As New NotesName ( doc1.GetItemValue("mailserver")) ***Error***

	servername = homeserver.abbreviated

	Print "ServerName" & servername

'Find Mailfile field values from Person document

	Print "Extracting Mailfile path from Person Document"		

	mailfile = doc1.GetItemValue("mailfile")

	Print "Persons Mailfile Path is " & mailfile(0)

'Get database to create document in

	Set destdb = session.GetDatabase( servername , mailfile(0))

	Set doc = db.GetDocumentByID(agent.ParameterDocID)	

'Create mini-doc

	Set doc2 = New NotesDocument(destdb)

	Set item = doc.GetFirstItem("$Alarm")

	Call item.CopyItemToDocument(doc2, "$Alarm")

	Set item = doc.GetFirstItem("$AlarmOffset")

	Call item.CopyItemToDocument(doc2, "$AlarmOffset")

	If doc.HasItem("RepeatDates") Then

		Set item = doc.GetFirstItem("RepeatDates")

	Else

		Set item = doc.GetFirstItem("CalendarDateTime")	

	End If

	Call item.CopyItemToDocument(doc2, "CalendarDateTime")

	Call item.CopyItemToDocument(doc2, "PostedDate")

	Set item = doc.GetFirstItem("Subject")

	Call item.CopyItemToDocument(doc2, "Subject")		

'Save and move mini-doc to folder

	Call doc2.Save(True , False , True)

	Call doc2.PutInFolder ("($Alarms)")

	

End Forall

ErrHandler:

Print "Got Error " & Cstr( Err() ) & " " & Error() & " in line: " & Cstr( Erl() )

Resume Next

End Sub

Subject: RE: Got Error 13 Type mismatch in line: 47

NotesItems other than Rich Text and special error values ALWAYS return a Variant containing an array of values – even if that array only has one member. NotesName takes a String as a parameter, not an array. Use:

Dim homeserver As New NotesName ( doc1.GetItemValue(“mailserver”)(0))

Note that the zeroeth element of the values array is being used rather than the array itself.

Subject: All working - sort of

Brilliant, it returns a value.

I had to swap Abbreviated for Common, to just get servername.