lotus script for date comparison with message box

Experts, I need this turned into a real script:
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
 
If Source.Document.HireDate > Now Then
messagebox
continue=false
end if

End Sub

This is for a view if the hiredate is not today or greater then a message box stating that person is expected to start on whatever the hiredate field says else allow the doc to open
padillrrProject CoordinatorAsked:
Who is Participating?
 
qwaleteeCommented:
Whoa! Not enough info.  Is this for creating a new document of some sort base don another doc that includes a hire date?  Is this for opening an existing doc that contains a hire date?  The latter doesn't make much sense to me, but this is what would do it:

TomorrowDate = Today + 1
HireDateValue = Source.Document.HireDate(0)
If HireDateValue >= TomorrowDate Then
  messagebox "Hire date has not occured.  Please wait until " & cstr(HireDateValue) _
  & " ... you cannot open the document until then."
  continue=false
end if




Also, this statement seems backward:
if the hiredate is not today or greater then a message box stating that person is expected to start on whatever the hiredate field says

if the hiredate is not today or greater = hiredate already occured
if the hiredate IS today or greater = hiredate is still in the future (or at least present)
So, wouldn't you want to give message box about EXPECTED to start if the hiredate is greater than today????

0
 
Bill-HansonCommented:
I don't really care why you want to do this but here's how you do it...

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
      
      If (Not Source.IsNewDoc) Then
            Dim hireDate As NotesDateTime
            Dim nowDate As NotesDateTime
            Set hireDate = DtGetLsDateTime(Source.Document.GetItemValue("HireDate")(0))
            Set nowDate = DtGetLsDateTime(Now)
            If (DtGetDaysDifference(hireDate, nowDate) < 0) Then
                  Msgbox "No!"
                  Continue = False
            End If
      End If
      
End Sub

... You'll also need these support functions.  Add them to your library!

Function DtGetDaysDifference(dtSource1 As NotesDateTime, dtSource2 As NotesDateTime) As Integer
      
      '/**
      ' * Determines the number of days between the two dates.
      ' * @param dtSource1 The first date.
      ' * @param dtSource2 The second date.
      ' * @return The number of days by which the two dates differ.  If Source1 is before Source2 the return value will be positive.  If Source1 is after Source2 the return value will be negative.  If the days are the same, the return value will be zero.
      ' */
      
      Const SECONDS_PER_DAY = 86400
      Dim dtDate1 As New NotesDateTime(dtSource1.DateOnly)
      Dim dtDate2 As New NotesDateTime(dtSource2.DateOnly)
      DtGetDaysDifference = (dtDate2.Timedifference(dtDate1) / SECONDS_PER_DAY)
      
End Function

Function DtGetLsDateTime(value As Variant) As NotesDateTime
      
      '/**
      ' * Creates a date time object from a LotusScript value.
      ' * @param value A LotusScript date/time value.
      ' * @return The value contained in a NotesDateTime object.
      ' */
      
      Set DtGetLsDateTime = New NotesDateTime("")
      If Isdate(value) Then DtGetLsDateTime.LSLocalTime = value
      
End Function
0
 
qwaleteeCommented:
Isn't that a little complicated for something where you can just compare values directly?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
Bill-HansonCommented:
Wow, I can't believe that I never tested this myself.  I always assumed that direct manipulation of DateTime was not allowed in LotusScript.  Are you sure that this is officially supported?
0
 
qwaleteeCommented:
A date field returns an array of variants each of which is a Lotusscript time value. You can get at the underlying, more-complex Notes date value using the DateTimeValue property of the item, but it is normally so much easier to just treat the field as an array of scalars, same as any other regular field vale in Notes translates into a Lotusscript array of scalars.

Yes, definitely supported.  Go to designer help, Values property (of NotesItem). First table shows the data type for reading.  Includes a row:
Date-time or range of date-time values      Array of Variant of type DATE. A scalar value is a 1-element array.

And of course, VALUES maps into the late-binding document dynamic property for field names.


Hmm, I think I just saved you a lot of coding. If it is any indication, my 7 lines is the same as your 18.  Enjoy!
0
 
padillrrProject CoordinatorAuthor Commented:
First thanks for the responses but maybe I need to explain the reason for this....I have an application that HR uses for Employee information, I then grab certain non sensitive data and using an agent populate an Employee lookup (sort of a nab) the is veiwable by all our employees but it is not editable by anyone. I also use this Employee lookup as my feed for our other applications, i.e. I populate manager fields, department information,  etc.  THe problem I am facing is that HR adds the new hires to the Employee Information system (EIS) once they have accepted the position which is proper procedure, this allows the manager to submit request for equipment phone lines etc. but what happens is that employees will start trying to contact this person before they are in the building, which sometimes can be up to 2 weeks. So what I want if for the persons name to show up on the view but when somebody tries to open that particular record if the hire date has not yet passed they get a pop up displaying the date that person is to be in the building, which is the hire date.....hope this better explains my need. I was looking at the Queryopenview as the trigger for the pop up and the lock on the record....
0
 
padillrrProject CoordinatorAuthor Commented:
This is my script:
Sub Queryopendocument(Source As Notesuiview, Continue As Variant)
      
      Dim docs As NotesDocumentCollection
      Dim doc As NotesDocument
      Dim item As NotesItem
      
      Set docs = Source.Documents
      Set doc = docs.GetFirstDocument
      
      TomorrowDate = Today + 1
      HireDateValue = Source.Document.HireDate(0)
      If HireDateValue >= TomorrowDate Then
            Messagebox " This Employee Document will not be available until " & Cstr(HireDateValue)
            continue=False
      End If
      
End Sub

getting the error NOT A MEMBER Document on line 11
0
 
Bill-HansonCommented:
The problem here is in your treatment of Source on line 11.  Source is now a Notesuiview, not a NotesUiDocument.  Try this...

Sub Queryopendocument(Source As Notesuiview, Continue As Variant)
     
      Dim docs As NotesDocumentCollection
      Dim doc As NotesDocument
     
      Set docs = Source.Documents
      Set doc = docs.GetFirstDocument
     
      TomorrowDate = Today + 1
      HireDateValue = doc.HireDate(0)
      If HireDateValue >= TomorrowDate Then
            Messagebox " This Employee Document will not be available until " & Cstr(HireDateValue)
            continue=False
      End If
     
End Sub
0
 
padillrrProject CoordinatorAuthor Commented:
Thanks Bill and Qwa
That worked perfectly anyway I can get rid of the time and just display the date?
0
 
Bill-HansonCommented:
Look at the Format function.  It does the same thing as Cstr, but it has options.
0
 
padillrrProject CoordinatorAuthor Commented:
can you please explain?!?! are you saying to call the function instead of the Cstr in order to remove the time ?
0
 
padillrrProject CoordinatorAuthor Commented:
never mind thanks guys I got it changed the Cstr to Cdat and it worked !!! thanks again!
0
 
Bill-HansonCommented:
Cdat worked because it converted the DateTime to a Date, then the concatenation operator (&) converted that Date back to a String.  It's more efficient to use the Format function because only one conversion takes place.  Plus, you can format the date any way you want.

Messagebox " This Employee Document will not be available until " & Format(HireDateValue, "MMDDYYYY")
0
 
qwaleteeCommented:
Thi is more complicated than you need.  A warning column in the view owuld have proably sufficed and been a lot simpler.  FOr that matter, you could have put the hire date in the view, and used selective coloring to highlight the value when it is in the future.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.