Unknown Property - PLEASE HELP

After upgrading to ND6 we can’t run the following agent without getting an unknown property error.

PLEASE HELP

AGENT:

Sub Initialize

Dim session As New NotesSession



Dim contkey As String



Set db = session.currentdatabase

Set actview = db.GetView("(ActivitiesToBeAdded)")

'actview.autorefresh = False



Set actdoc = actview.GetFirstDocument

If Not actdoc Is Nothing Then

	contkey = actdoc.ContactKey(0)

End If

Do While Not actdoc Is Nothing

	Set nextactdoc = actview.GetNextDocument(actdoc)

	If nextactdoc Is Nothing Then

		nextcontkey = ""

	Else

		nextcontkey = nextactdoc.ContactKey(0)

	End If

	If contkey <> nextcontkey Then

		Call UpdateContactDocument(contkey)

		'Call MarkActivitiesUpdated(contkey)

	End If

	Set actdoc = nextactdoc

	contkey = nextcontkey

Loop

Dim agentLog As New NotesLog("Agent log") 

Call agentLog.OpenAgentLog

Set s = New NotesSession

Set db = s.CurrentDatabase

Set collection = db.UnprocessedDocuments

Set note = collection.GetFirstDocument

count = collection.Count

Do While (count > 0)

	Subject = note.Subject

	Call agentLog.LogAction( "Processing: "+Subject(0))

	Set note = collection.GetNextDocument (note)

	count = count - 1

Loop

Call agentLog.Close

End Sub

Sub UpdateContactDocument(contkey As String)

Dim session As New NotesSession

Dim contview As NotesView

Dim contdoc As NotesDocument

Dim ViewName As String

Dim KeyValue As String

Dim rtitem As Variant

Dim UserName As String



Set contview = db.GetView("(ContactsByKey)")

Set contdoc = contview.GetDocumentByKey(contkey)

If contdoc Is Nothing Then

	Exit Sub

End If



'Drop the rich text fields from the document.  These will be rebuilt in this routine:

Call contdoc.RemoveItem ("UserComments")

Call contdoc.RemoveItem ("UserComments2")

Call contdoc.RemoveItem ("UserComments3")

Call contdoc.RemoveItem ("UserComments4")



Call contdoc.RemoveItem ("ProspectComments")

Call contdoc.RemoveItem ("ProspectComments2")

Call contdoc.RemoveItem ("ProspectComments3")

Call contdoc.RemoveItem ("ProspectComments4")



Call contdoc.RemoveItem ("ProjectComments")

Call contdoc.RemoveItem ("ProjectComments2")

Call contdoc.RemoveItem ("ProjectComments3")

Call contdoc.RemoveItem ("ProjectComments4")



Call contdoc.RemoveItem ("CompComments")

Call contdoc.RemoveItem ("CompComments2")

Call contdoc.RemoveItem ("CompComments3")

Call contdoc.RemoveItem ("CompComments4")



'Get fields from the form:

ContactKey = contkey

UserName = session.commonusername



'Set the All company comments field:	

ViewName = "(ActivitiesByContactKeyCompleted)"

KeyValue = ContactKey

Call GetSelectedComments (contdoc, ViewName, KeyValue, db, "CompComments")



'Set the Comments by User field:

ViewName = "(ActivitiesByCreatedByCompleted)"

KeyValue = ContactKey & UserName

Call GetSelectedComments (contdoc, ViewName, KeyValue, db, "UserComments")



'Set the Projects comments field:

ViewName = "(ActivitiesByContactKeyProjectCompleted)"

KeyValue = ContactKey

Call GetSelectedComments (contdoc, ViewName, KeyValue, db, "ProjectComments")



'Set the Prospects comments field:

ViewName = "(ActivitiesByContactKeyProspectCompleted)"

KeyValue = ContactKey

Call GetSelectedComments (contdoc, ViewName, KeyValue, db, "ProspectComments")



Call Contdoc.Save(True,True)

'now remove the activities from the view

Call MarkActivitiesUpdated(contkey)

End Sub

Sub GetSelectedComments (doc As NotesDocument, ViewName As String, KeyValue As String, db As NotesDatabase, rtfield As String)

Dim ActivityDocCollection As Notesdocumentcollection

Dim rtitem As NotesRichTextItem

Dim rtitemA As Variant

Dim CreatedBy As String

Dim f As String

Dim g As String

Dim view As NotesView

Set view = db.GetView(ViewName)

Dim proj As String

Dim sActivityDocCollection As NotesDocumentCollection

Set ActivityDocCollection = view.GetAllDocumentsByKey (KeyValue, True)



Dim sortdocs() As NotesDocument



Call CollectionToSortedArray (ActivityDocCollection, sortdocs)

Set rtitem = New NotesRichTextItem ( doc, rtfield )



Dim x As Integer

Dim ActivityDoc As NotesDocument



ub% = Ubound(sortdocs) - 1



For m=0 To ub%

	Set ActivityDoc = ActivityDocCollection.GetNthDocument(x)   'is this being overwritten by the next line?

	Set ActivityDoc = sortdocs(m) 'viewf.GetNthDocument(x)

	

	

	Set rtitemA = Activitydoc.GetFirstItem( "Comments" )

	If Not (Isnull (rtitemA)) Then

		rtitemA_text = rtitemA.GetFormattedText(False,0) 

		rtitem_text = rtitem.GetFormattedText(False,0) 

		textlen = Len(rtitem_text & Chr(13) & rtitemA_text) 

		If textlen > 6500 Then

				'check the field we are on 

			subscript = Right(rtitem.name,1)

			If Not Isnumeric(subscript) Then

				rtfield  = rtfield & "2"

			Elseif Cint(subscript) < 4 Then

				subscript = Cstr(Cint(subscript) + 1)

				rtfield = Mid(rtfield,1,Len(rtfield) -1) & subscript

			End If

			

			Set rtitem = New NotesRichTextItem ( doc, rtfield )				

		End If

		Call rtitem.AddNewLine(2)

		If Trim$(ActivityDoc.ActCreatedBy(0)) = "" Then

			CreatedBy = ActivityDoc.Authors (0)

		Else

			CreatedBy = ActivityDoc.ActCreatedBy (0)

		End If

		g = ActivityDoc.CompletedDate(0)

		'Was ApptDate, changed to completedDate

’ f = ActivityDoc.FollowUpDate(0)

'tried switching g and f. Made g ApptDate and F FollowUpdate

’ If g = “” Then

’ g = f

’ End If

		If ActivityDoc.Project(0) = "" Then 

			proj="" 

		Else 

			proj ="Project: " & ActivityDoc.Project(0)   

		End If

’ Call rtitem.AppendText(ActivityDoc.ApptDate(0) & " - " & CreatedBy & " (" & ActivityDoc.ActivityType (0) & ") ")

’ Call rtitem.AppendText(ActivityDoc.ApptDate(0) & " - " & CreatedBy & " (" & ActivityDoc.ActivityType (0) & “-”& ActivityDoc.Actions(0) & ") ")

		Call rtitem.AppendText( g & " - " & CreatedBy & "  (" & ActivityDoc.ActivityType (0) & "-"& ActivityDoc.Actions(0) & ")  " & proj & ""& ActivityDoc.Sector(0))

		Call rtitem.AddNewLine(1)

		

		Call rtitem.AppendRTItem( rtitemA )

	End If

	

Next

’ Call ActivityDocCollection.RemoveAllFromFolder(folder$)

End Sub

Sub CollectionToSortedArray(col As NotesDocumentCollection, docs() As NotesDocument)

Dim i As Integer

Dim doc As NotesDocument

Dim n As Integer, sorted As Integer

Dim s1, s2 As String



n = col.count

Redim docs(n) As NotesDocument

’ push to array

For i = 0 To n - 1

	Set docs(i) = col.GetNthDocument(i+1)

Next

'bubble sort array

sorted = False

Do While (sorted = False)          

	sorted = True

	For i = 0 To n - 2

 ' sort based on CompletedDate

		

		If docs(i+1).CompletedDate(0) > docs(i).CompletedDate(0) Then

'original If(Strcomp(s2, s1, 5) = 1) Then 'No Pitch, No Case Compare

			Call Swap(docs(i),docs(i+1))

			sorted = False

		End If

	Next

Loop

End Sub

Sub Swap(doc1 As NotesDocument ,doc2 As NotesDocument)

Dim d As NotesDocument

Set d = doc1

Set doc1 = doc2

Set doc2 = d     

End Sub

Sub MarkActivitiesUpdated(contkey As String)

Set actdc = actview.GetAllDocumentsByKey(contkey)

For i = 1 To actdc.count

	Set actdoc = actdc.GetNthDocument(i)

	actdoc.UpdateContactFlag = "0"

	Call actdoc.Save(True,True)

Next

End Sub

Subject: Unknown Property - PLEASE HELP

Hi Charles,

are you sure that in the document you are working on the item “UserComments” is in? It´seems that the item is not in and the error occurs, because you´ll try to remove a non existent item :slight_smile:

It´s only a guess, try to find out in the debugger.

Kai

Subject: I see 1 thing that is goofy…

Sub UpdateContactDocument(contkey As String)

Dim session As New NotesSession

Dim contview As NotesView

Dim contdoc As NotesDocument

Dim ViewName As String

Dim KeyValue As String

Dim rtitem As Variant

Dim UserName As String



Set contview = db.GetView("(ContactsByKey)")

Set contdoc = contview.GetDocumentByKey(contkey)

If contdoc Is Nothing Then

	Exit Sub

End If

You never Dim or Set db to anything. Can you also verify that in the Debugger, when you look at the variable contdoc that it shows up as a NotesDocument in the variable type column.

Subject: RE: I see 1 thing that is goofy…

Can you reccomend something? Thanks!!!

Subject: Is there anything in the Declarations section of the Agent?

Subject: RE: Is there anything in the Declarations section of the Agent?

NO (EOM)

Subject: Then you should be getting the error on the line: Set contview = db.GetView(“(ContactsByKey)”)

My suggestion is that you use global variables when possible. In the Declarations section of the agent the following:Dim session As NotesSession

Dim db As NotesDatabase

Then in the first 2 lines of the Initialize (replacing the Dim session)

Set session = New NotesSession

Set db = session.CurrentDatabase

Now remove all Dims of session in your remaining Subs, also remove the passing of the db into the GetSelectedComments sub.

Subject: Unknown Property - PLEASE HELP

Did you run it with the LS Debugger on to try and narrow down where the error is occurring?

Subject: RE: Unknown Property - PLEASE HELP

Yes,

Error is occuring here:

Event: UpdateContactDocument

Call contdoc.RemoveItem (“UserComments”)

Breakpoint:

Main: UpdateContactDocument:18

Main: UpdateContactDocument:19

and so on through the code.

ANY IDEAS?