Hours in day

Hello,I have a database in which the users register their time on projects.

Currently there is no error checking to stop the users from placing two time entries in which the sum of which would be greater than 8 hours.

I have a view of the documents Categorized by the Employee. The view has two other columns date (pulled from the date field on doc) and hours(pulled from the hours field on the doc)

What I am trying (unsure if it will work) is to in a postsave event have a GetAllDocumentsbyKey(date) ← using the date field. Get the total of the columnvalue for hours for that date. If the sum of this plus the existing documents field value for hours is greater than 8 I want to give the users a messagebox and cancel the save.

Subject: Hours in day

Hi there

You would be better of using the “querysave” event. This will stop the save event from occuring. Something along the lines of

Sub Querysave(Source As Notesuidocument, Continue As Variant)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim timeTotal As Integer

searchFormula$ = { Form = “FormName” & person = @Name([CN];@UserName) & workDate = @Today }

Set db = session.CurrentDatabase

Set collection = db.Search(searchFormula$, Nothing, 0)

Set doc = collection.GetFirstDocument()

While Not(doc Is Nothing)

timeTotal = timeTotal + doc.timeFieldValue(0)

Set doc = collection.GetNextDocument(doc)

Wend

timeTotal = timeTotal + Cint( source.fieldGetText( “timeFieldValue” ) )

If timeTotal > 8 Then

Messagebox " you are working too hard"

Continue = False

Exit Sub

End If

End Sub

I’m not sure how you are entering your ‘time spent’ value, but this would work for hours. You could get the user to enter minutes and test against 480 minutes.

HTH

andyg

Subject: RE: Hours in day

HelloThis works perfectly. Thanks

I see only one issue the part of the search string

workDate = @Today the form the users are filling out has a date picker to choose to put the hours on another day. Currently with the @today no mater what date they choose in the date field they get the 24 hour message

Is there a way aroud this? Will the searchFormula and document collection work with FieldGetText on the Date field?

Subject: RE: Hours in day

I figured it out thanks

Dim datefield as variant

set datefield = doc.date(0)

searchFormula$ = { Form = “HR” & Employee = @Name([CANONICALIZE];@UserName) & Date = [} & Datefield & {]}

Subject: RE: Hours in day

one thing, always check the UNID of the document you are saving against the document from the collection, that way you won’t add the same hours twice (in the case of an edit and not a new doc).

Subject: RE: Hours in day

Helloyou are right I have that exact issue now. I am very green at this. How would i get stated checking the unid of the document. I have an if statement now for existing docs.

If uidoc.isnotnewdoc

Subject: RE: Hours in day

hi again

you could get the unid with

Dim sourceUnid As string

sourceUnid = source.document.universalID

and then modifiy the while statement

While Not(doc Is Nothing)

if (sourceUnid <> doc.universalID) then

timeTotal = timeTotal + doc.timeFieldValue(0)

end if

Set doc = collection.GetNextDocument(doc)

Wend

And still add the time amount for the source document after.

There should be no need to test for the new document, as testing the universal ID should identify if the document is already in the collection.

HTH

cheers

andyG

Subject: RE: Hours in day

HiThanks Again. I am a newbie at this but hope to get better :slight_smile: