Help! Lotus Script Date Comparison

Hi All,

My first post here, and its a request for help I’m afraid.

I am pretty familiar with Formulae Language in Notes, but have rarely dipped my toe in the pool of Lotus Script.

I find now, that I need to write an agent that does the following.

Checks each document for the following.

Compares a ‘FinishDate’ field(Date field type) in a document with Todays date.

If Todays Date is after the ‘FinishDate’ in the Document then I wish to modify a ‘Status’ Text field in the document to read “complete”

I tried to write this in formulae language but got nowhere.

Can anyone assist?

Subject: Help! Lotus Script Date Comparison

here is the code to compare the dates…

Set dtToday = New NotesDateTime(Today)

set doc = docCollection.GetFirsstDocument()

while not doc is nothing then

 Set itemDate = doc.GetFirstItem("FinishDate")

 Set dtFinish = itemDate.DateTimeValue

 If dtFinish.TimeDifference(dtToday) < 0 Then

       'change the status as completed here

 End If

 set doc = docCollection.getNextDocument(doc)

wend

hope this helps u…

Thanks & Regards

Malathy

Subject: RE: Help! Lotus Script Date Comparison

Hi Malathy,

This line

“set doc = docCollection.GetFirstDocument()”

causes the following error.

“Variant does not contain an object”

I assume I need to define what docCollection is.

(if it helps I am running Notes 6.5 )

thanks :slight_smile:


Set dtToday = New NotesDateTime(Today)

set doc = docCollection.GetFirstDocument()

while not doc is nothing

Set itemDate = doc.GetFirstItem(“FinishDate”)

Set dtFinish = itemDate.DateTimeValue

If dtFinish.TimeDifference(dtToday) < 0 Then

'change the status as completed here

End If

set doc = docCollection.getNextDocument(doc)

wend

Subject: RE: Help! Lotus Script Date Comparison

Hi Its collection of documents what u need to process(which is of type NotesDocumentCollection). I just sent the part of the code… you get the desired documents thru view or some other way…

eg,

dim view as NotesView

dim Session as new NotesSession

dim Db as NotesDatabase

dim docCollection as NotesDocumentCollection

dimi doc as NotesDocument

set Db = Session.CurrentDatabase

set view = Db.GetView()

set docCollection = view.GetAllDocumentsByKey(,true)

set doc = docCollection.GetFirstDocument()

while not doc is nothing

Set itemDate = doc.GetFirstItem(“FinishDate”)

Set dtFinish = itemDate.DateTimeValue

If dtFinish.TimeDifference(dtToday) < 0 Then

'change the status as completed here

End If

set doc = docCollection.getNextDocument(doc)

wend

In case, any issue explain ur real scenario will try to help u if possible

Regards

Malathy

Subject: Help! Lotus Script Date Comparison

Why not use formula?

@if(FinishDate<@today;Status:=“Complete”;“”)

This would work in an agent either running against selected documents or scheduled against all docs in database

Dan

Subject: RE: Help! Lotus Script Date Comparison

Thanks all I will try these methods.

Subject: RE: Help! Lotus Script Date Comparison

field Status := @if([whateverdatefield] > @today; “Complete”; Status")

This will only update field status if condition is met, update the formula as needed.

Subject: RE: Help! Lotus Script Date Comparison

That’s true - mine should have said:

@if(FinishDate<@today;FIELD Status:=“Complete”;“”)

Forgot to set the field, rather than just a variable

Dan

Subject: RE: Help! Lotus Script Date Comparison

Finally Have it sorted. Thanks to everyone. You are all Great!!! :slight_smile: