Manage Learn to apply best practices and optimize your operations.

Web Based Calendar Control

In the Notes client you have calendar controls for date/time fields in layout regions; here's an agent that builds a calendar control for using on the Web.

' Create an agent using this code and call it by using a link on a web page that opens it up in its own window and having a parameter of &Field=FieldName where 'FieldName is the Name of the field in your form you want the date the user selects 'from this window to goto

' For example:
' Create a javascipt function on a html form like
' function ShowCalander(FieldName){
''/database.nsf/AgentName/?OpenAgent&Field=' + FieldName,'CalendarWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=320,height=200');

' And create a link a the form next to the field you want the calander to put its date into in the format <a onclick="ShowCalandar('FieldName')">Click</a>

' Code for Initialize method of agent

Dim Sess As New NotesSession()
Dim ThisDB As NotesDatabase
Dim AgentDoc As NotesDocument
Dim TodaysDate As NotesDateTime
Dim TimeNow As NotesDateTime
Dim FirstofMonth As NotesDateTime
Dim NextMonth As NotesDateTime
Dim LastMonth As NotesDateTime
Dim RowCounter As Integer
Dim DayNum As Integer
Dim MonNum As Integer
Dim YearNum As Integer
Dim ThisMonth As String
Dim ParseInt As Integer
Dim ParseString,FieldName,DateString As String
Dim BackLink,NextLink As String

DateString = ""

Set AgentDoc = Sess.DocumentContext
Set ThisDb = AgentDoc.ParentDatabase
' Get the field name and the date required from the URL string

ParseInt = Instr(AgentDoc.Path_Info(0), "&Field=")

If ParseInt = 0 Then Print "You must run this agent with a ""Field"" parameter or the calendar does not know which field to place the data in the parent window"
Exit Sub
End If

ParseString =Right(AgentDoc.Path_Info(0),Len(AgentDoc.Path_Info(0)) - ParseInt -6 )

ParseInt = Instr(ParseString, "&Date=")

If ParseInt = 0 Then

FieldName = Trim(ParseString)


FieldName = Left(ParseString, ParseInt- 1)

DateString = Right(ParseString,Len(ParseString) - ParseInt -5 )

End If

' If the URL has not given us a date assume today
If DateString = "" Then
Set TodaysDate = New NotesDateTime("")
Call TodaysDate.SetNow
Set FirstofMonth=New NotesDateTime("")
Call FirstofMonth.SetNow
Set NextMonth=New NotesDateTime("")
Call NextMonth.SetNow
Set LastMonth=New NotesDateTime("")
Call LastMonth.SetNow


Set TodaysDate = New NotesDateTime(DateString)
Set FirstofMonth = New NotesDateTime(DateString)
Set LastMonth = New NotesDateTime(DateString)
Set NextMonth = New NotesDateTime(DateString)

End If

' Set lastMonth to be a month ago
Call LastMonth.AdjustMonth(-1)

' Set NextMonth to be a month ahead Call NextMonth.AdjustMonth(1)

Set TimeNow = New NotesDateTime("") Call TimeNow.SetNow

MonNum = Month(TodaysDate.lslocaltime)
YearNum = Year(TodaysDate.lslocaltime)
'Find out how many days this is front the start of the Month
DayNum = Day(TodaysDate.lslocaltime)

Select Case MonNum

Case 1
ThisMonth = "January"
Case 2
ThisMonth = "February"
Case 3
ThisMonth = "March"
Case 4
ThisMonth = "April"
Case 5
ThisMonth = "May"
Case 6
ThisMonth = "June"
Case 7
ThisMonth = "July"
Case 8
ThisMonth = "August"
Case 9
ThisMonth = "September"
Case 10
ThisMonth = "October"
Case 11
ThisMonth = "November"
Case 12
ThisMonth = "December"
End Select
' Now adjust FirstofMonthBack to the start of the month
Call FirstofMonth.AdjustDay(1-DayNum)

Print "<HTML>"
Print "<HEAD>"

' Print the javascript function to send the date selected back to the parent window and close the calendar window
Print "<SCRIPT>"
Print "function DateSetter(Date)"
Print "{"
Print "window.opener.document.forms[0]." + FieldName + ".value=Date;"
Print "window.close()"
Print "}"
Print "</SCRIPT>"
Print "</HEAD>"
Print "<TR>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1 COLOR=""BLUE""><A HREF=""/" + ConvtoURLString(ThisDB.FilePath) + "/CalendarWindow/?OpenAgent&Field=" + _ FieldName + "&Date=" + LastMonth.DateOnly + """>>></A></TD>"

Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1 COLOR=""BLUE""><CENTER>" + ThisMonth + " - " + Cstr(YearNum) +"</CENTER></FONT></B></TD>"

Print "<TD ALIGN=""RIGHT""><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1 COLOR=""BLUE""><A HREF=""/" + ConvtoURLString(ThisDB.FilePath) + "/CalendarWindow/?OpenAgent&Field=" + _
FieldName + "&Date=" + NextMonth.DateOnly + """>>></A></TD>"

Print "<TR>"
Print "</TABLE>"

Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Sun  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Mon  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Tue  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Wed  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Thu  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Fri  </FONT></B></TD>"
Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1>  Sat  </FONT></B></TD>"
Print "</TR>"

RowCounter = 1

Print "<TR>"
' Now Build up the spaces for the forst row of the calendar that pad before the first day
While RowCounter < Weekday(FirstofMonth.lslocaltime)
RowCounter = RowCounter + 1

' Now Buildup the rest of the calendar for this month

While Month(FirstofMonth.lslocaltime) = MonNum

If Month(TimeNow.lslocaltime) = Month(FirstofMonth.lslocaltime) And Year(TimeNow.lslocaltime) = Year(FirstofMonth.lslocaltime) And Day(TimeNow.lslocaltime) = Day(FirstofMonth.lslocaltime) Then

Print "<TD><B><FONT FACE=""TAHOMA,ARIAL"" SIZE=1><CENTER><A HREF=""javascript:DateSetter('" +FirstofMonth.DateOnly + "')"">" + Cstr(Day(FirstofMonth.lslocaltime)) + "</A></B></CENTER></FONT></TD>"


Print "<TD><FONT FACE=""TAHOMA,ARIAL"" SIZE=1><CENTER><A HREF=""javascript:DateSetter('" +FirstofMonth.DateOnly + "')"">" + Cstr(Day(FirstofMonth.lslocaltime)) + "</A></CENTER></FONT></TD>"

End If

RowCounter = RowCounter + 1

' If we are at the end of a row then print out the end of row marker and start a new row
If RowCounter = 8 Then
RowCounter = 1
Print "</TR>"
Print "<TR>"
End If
' Now Move to the nextday
Call FirstofMonth.AdjustDay(1)

' and Finally fill in the boxes that are blank at the end
While RowCounter < 8

RowCounter = RowCounter + 1


Print "</TR>"
Print "</TABLE>"
Print "</BODY>"
Print "</HTML>"

This was last published in November 2000

Dig Deeper on Domino Resources - Part 6

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...