Get Field problem

Hi,

With the help of another user on this forum, I have created an agent with the following code which will append to a text list:

Sub Initialize

Dim s As New NotesSession

Dim db As NotesDatabase

Set db = s.CurrentDatabase

Dim docCollection As NotesDocumentCollection

Dim doc As NotesDocument



Set docCollection = db.UnprocessedDocuments

Set doc = docCollection.GetFirstDocument



Do Until doc Is Nothing

’ …set value of doc…

	Set item = doc.GetFirstItem( "Approvals" )

	Call item.AppendToTextList("Lead Branch: BST")		

	Call item.AppendToTextList( "Deputy Secretary" )

	Call item.AppendToTextList("Author: Jason Sas")

	Call doc.Save( False, True )

	Set doc = docCollection.GetNextDocument(doc)

Loop 

End Sub

I’d like to modify this slightly by having the agent get the value of a field in the document and then use this when appending to the text list. For example, in the code above I am updating the text list with the “Lead Branch: BST”, which I have actually typed into agent. I know that there is a field in the document called ‘LeadBranch’ with the value of BST in it. I’d like the code to grab this value and update the text list with the words ‘Lead Branch’, plus the value in the field.

I had a look at the FieldGetText method, but this seems to apply to a NotesUIDocument, not a NotesDocument.

Thanks in advance

Subject: Get Field problem

“Elementary Lotusscript, my dear” :slight_smile:

Dim s As New NotesSession

Dim db As NotesDatabase

Set db = s.CurrentDatabase

Dim docCollection As NotesDocumentCollection

Dim doc As NotesDocument

Set docCollection = db.UnprocessedDocuments

Set doc = docCollection.GetFirstDocument

Do Until doc Is Nothing

’ …set value of doc…

Set item = doc.GetFirstItem( “Approvals” )

Call item.AppendToTextList(Lead Branch " + doc.LeadBranch(0))

Call item.AppendToTextList( “Deputy Secretary” )

Call item.AppendToTextList(“Author: Jason Sas”)

Call doc.Save( False, True )

Set doc = docCollection.GetNextDocument(doc)

Loop

End Sub

That is assuming that leadbranch only has one value.

Subject: RE: Get Field problem

Hi marjan,

Thanks for your help. as I’m such a total newbie to Notes, I’m not sure why LeadBranch is listed with (0), but I won’t question it because it’s working!! haha!1

I have another question. The agent may also need to append the text list with Liaison Branches. A Liaison Branch may or may not be listed (hence it will have a field value of “”), or it may also have one or more Liaison Branches.

Is there a way to first of all find out if there are any Liaison Branches listed and if so, update one or more of those branches to the text list. The field for Liaison Branch is ‘LiaisonBranches’.

Thanks for your help so far.

Subject: RE: Get Field problem

Dim s As New NotesSessionDim db As NotesDatabase

Set db = s.CurrentDatabase

Dim docCollection As NotesDocumentCollection

Dim doc As NotesDocument

Set docCollection = db.UnprocessedDocuments

Set doc = docCollection.GetFirstDocument

Do Until doc Is Nothing

’ …set value of doc… Set item = doc.GetFirstItem ( “Approvals” )

Call item.AppendToTextList(Lead Branch " + doc.LeadBranch(0))

if doc.Liaisonbranches(0) <> “” then

forall L in doc.Liaisonbranches(0)

   Call item.AppendToTextList(Liaison Branch " + L) 

end forall

end if

Call item.AppendToTextList( “Deputy Secretary” )

Call item.AppendToTextList(“Author: Jason Sas”)

Call doc.Save( False, True )

Set doc = docCollection.GetNextDocument(doc)

Loop

End Sub

Something like the above would do the trick but maybe Lotusscript course would do you more good!