Simple LS agent assistance please

I can’t seem to get this script to work correctly. Any help would be most appreciated.

Here’s what I’m looking for it to accomplish:

  1. Go through the database and when it finds the form ‘Opportunity’ determine if it was created more than 9 months ago (I have it set for three days for testing purposes).

  2. If it was created more than ‘three days ago’ then put the word ‘red’ in the text field called ‘OppAge’.

  3. Go to the next document and repeat.

That’s it. So far it works, but when it comes to putting the text into the field it either isn’t saving correctly or I’m just not putting the value in correctly.

Thank you for any help that is offered.

Sub Initialize

Dim s As New NotesSession

Dim doc As NotesDocument

Dim dc As NotesDocumentCollection

Dim db As NotesDatabase

Dim i As Integer

Dim CreatedDate As NotesDateTime

Dim CurrentDate As NotesDateTime

Dim ModifiedDate As NotesDateTime

Dim Item As String



Set db = s.currentdatabase

Set dc = db.alldocuments

Set doc = dc.GetFirstDocument

Set CurrentDate = New NotesDateTime(Today)	

Call CurrentDate.AdjustDay( -3 )  

For i = 1 To dc.count

	Set CreatedDate = New NotesDateTime(doc.Created)		

	If CurrentDate.TimeDifference( CreatedDate ) > 0  Then

		doc.OppAge = "red"

		Call doc.Save(True, True)

	End If

Next

End Sub

Subject: Simple LS agent assistance please.

You have to get the document in the loop to update else it is in only one document the first one it checks

For i = 1 To dc.count

doc = dc.GetNthDocument(i)

Set CreatedDate = New NotesDateTime(doc.Created)

If CurrentDate.TimeDifference( CreatedDate ) > 0 Then

doc.OppAge = “red”

Call doc.Save(True, True)

End If

Next

HTH

Keshava

Subject: Simple LS agent assistance please.

I REALLY appreciate everyone’s help. I did make the change and it works great.

I love the Lotus community and the help that we are all willing to give one another.

Subject: Simple LS agent assistance please.

You have to set the doc value inside the for loop as you code is updating only one document as

Set doc = dc.GetFirstDocument

cheers

Raj

Subject: RE: Simple LS agent assistance please.

He’s quite correct.

Set doc = dc.GetFirstDocument

Set CurrentDate = New NotesDateTime(Today)

Call CurrentDate.AdjustDay( -3 )

while Not (doc is nothing)

Set CreatedDate = New NotesDateTime(doc.Created)

If CurrentDate.TimeDifference( CreatedDate ) > 0 Then

doc.OppAge = “red”

Call doc.Save(True, True)

End If

'Add this

Set doc = dc.GetNextDocument(doc)

wend

Subject: Need to get Next Document…

For i = 1 To dc.count		Set CreatedDate = New NotesDateTime(doc.Created)		

	If CurrentDate.TimeDifference( CreatedDate ) > 0  Then

		doc.OppAge = "red"

		Call doc.Save(True, True)

	End If

	Set doc = dc.GetNextDocument(doc)

Next

Subject: this shud work…

Sub Initialize

Dim s As New NotesSession

Dim doc As NotesDocument

Dim tempdoc As notesdocument

Dim dc As NotesDocumentCollection

Dim db As NotesDatabase

Dim i As Integer

Dim CreatedDate As NotesDateTime

Dim CurrentDate As NotesDateTime

Dim ModifiedDate As NotesDateTime

Dim Item As String



Set db = s.currentdatabase

Set dc = db.alldocuments

Set doc = dc.GetFirstDocument

Set CurrentDate = New NotesDateTime(Today) 

Call CurrentDate.AdjustDay( -3 ) 



While Not doc Is Nothing

	Set tempdoc=doc

	Set CreatedDate = New NotesDateTime(tempdoc.Created) 

’ If CurrentDate.TimeDifference( CreatedDate ) > 0 Then

	If CurrentDate.TimeDifference( CreatedDate ) > 0 And tempdoc.form(0)="Opportunity" Then

		tempdoc.OppAge = "red"

	End If

	Set doc = dc.getNextDocument(doc)

	Call tempdoc.Save(True, True)

Wend

End Sub