Rajen
asked on
Calendaring
Hi,
I have a requirement where user has to book rooms for some Briefing. At present Iam using a calendar to see the availability of the room for the date and time. But I want a way where when I enter the date and time, i should be given a message that the Room is available or not for that time and date. I tried using getdocumentbykey in script, taking the room name, date, starttime and endtime as key. But if the time say i am looking for is 10am to 12pm and if the room is booked from 10.30am tehn it fails and says the room is available. any suggestion is appreciated
Rajen
I have a requirement where user has to book rooms for some Briefing. At present Iam using a calendar to see the availability of the room for the date and time. But I want a way where when I enter the date and time, i should be given a message that the Room is available or not for that time and date. I tried using getdocumentbykey in script, taking the room name, date, starttime and endtime as key. But if the time say i am looking for is 10am to 12pm and if the room is booked from 10.30am tehn it fails and says the room is available. any suggestion is appreciated
Rajen
Hi Rajen !
Sometime back I was having a similar problem and the following was the solution I gave to the customer.
You should go for a lengthier script. Lemm give you the logic.
SORRY I dont have that code now.
Walk through the destination view with a do while last document. The view from which you are currently getting documentsbykey.
First compare the date you have with that of the date on the documents that are walked through.
sourcedate = targetdate then go in for the field comparisons
Your starttime should not fall between the timerange of the walked documents. So as your end time.
if
sourdestarttime > targetstarttime and sourcestarttime < targetendtime then
you have a conflict.
Similarly for the endtime
sourdeendtime > targetstarttime and sourceendtime < targetendtime then
you have a conflict.
When ever the date matches and the time
conflicts you are sure that the room is unavailable.
Good Luck !
Love,
Arun
Sometime back I was having a similar problem and the following was the solution I gave to the customer.
You should go for a lengthier script. Lemm give you the logic.
SORRY I dont have that code now.
Walk through the destination view with a do while last document. The view from which you are currently getting documentsbykey.
First compare the date you have with that of the date on the documents that are walked through.
sourcedate = targetdate then go in for the field comparisons
Your starttime should not fall between the timerange of the walked documents. So as your end time.
if
sourdestarttime > targetstarttime and sourcestarttime < targetendtime then
you have a conflict.
Similarly for the endtime
sourdeendtime > targetstarttime and sourceendtime < targetendtime then
you have a conflict.
When ever the date matches and the time
conflicts you are sure that the room is unavailable.
Good Luck !
Love,
Arun
ASKER
Hi, Arun Can you send the code.
Working on it. You will get it in a couple of hours.
:)
Arun
:)
Arun
Hi Rajen,
Please try the following code. The variables you have to change are :
BOOKINGSDATABASENAME.nsf --- The database name of the view from which you were trying the GetDocumentByKey
THEVIEWNAMEYOUWANTTOWALKTH ROUGH --- name of the view from which you were trying the GetDocumentByKey
STARTTIMEFIELDNAMEINYOURUI DOCUMENT --- start Time field name in your currentdocument
ENDTIMEFIELDNAMEINYOURUIDO CUMENT --- end time field name in your current document
STARTTIMEFIELDNAMEINYOURBO OKINGSDOCU MENT --- start time field name of the document that has to be checked
ENDTIMEFIELDNAMEINYOURBOOK INGSDOCUME NT --- end time field name of the document that has to be checked
DATEFIELDNAMEINYOURUIDOCUM ENT --- date field in your current document
DATEFIELDNAMEINYOURBOOKING SDOCUMENT --- date field in the document that has to be checked.
The code is not tested. But.....
:)
Arun
========================== ========== ====
Dim ss As New notessession
Dim ws As New notesuiworkspace
Dim targetdb As notesdatabase
Dim view As notesview
Dim uidoc As notesuidocument
Dim sourcedoc As notesdocument
Dim targetdoc As notesdocument
Dim sourcestarttime As Variant
Dim sourceendtime As Variant
Dim targetstarttime As Variant
Dim targetendtime As Variant
Dim sourcedate As Variant
Dim targetdate As Variant
Dim flag As String
Set uidoc = ws.Currentdocument
Set sourcedoc = uidoc.document
sourcestarttime = sourcedoc.STARTTIMEFIELDNA MEINYOURUI DOCUMENT(0 )
sourceendtime = sourcedoc.ENDTIMEFIELDNAME INYOURUIDO CUMENT(0)
sourcedate = sourcedoc.DATEFIELDNAMEINY OURUIDOCUM ENT(0)
Set targetdb = New notesdatabase(ss.CurrentDa tabase.Ser ver,"BOOKI NGSDATABAS ENAME.nsf" )
Set view = tardb.GetView("THEVIEWNAME YOUWANTTOW ALKTHROUGH ")
Set targetdoc = view.GetFirstDocument
flag = "Free"
Do While Not (targetdoc Is Nothing)
targetdate = targetdoc.DATEFIELDNAMEINY OURBOOKING SDOCUMENT( 0)
targetstarttime = targetdoc.STARTTIMEFIELDNA MEINYOURBO OKINGSDOCU MENT(0)
targetendtime = targetdoc.ENDTIMEFIELDNAME INYOURBOOK INGSDOCUME NT(0)
If sourcedate = targetdate Then
If ((sourcestarttime >= targetstarttime And sourcestarttime <= targetendtime)) Or ((sourceendtime >= targetstarttime And sourceendtime <= targetendtime)) Then
Messagebox "A room is already booked in the specified timeslot "
Exit Do
End If
End If
Set targetdoc = view.GetNextDocument(targe tdoc)
Loop
If flag = "Free" Then
Msgbox "No booking made to the room at the specified timeslot"
End If
========================== ==========
Please try the following code. The variables you have to change are :
BOOKINGSDATABASENAME.nsf --- The database name of the view from which you were trying the GetDocumentByKey
THEVIEWNAMEYOUWANTTOWALKTH
STARTTIMEFIELDNAMEINYOURUI
ENDTIMEFIELDNAMEINYOURUIDO
STARTTIMEFIELDNAMEINYOURBO
ENDTIMEFIELDNAMEINYOURBOOK
DATEFIELDNAMEINYOURUIDOCUM
DATEFIELDNAMEINYOURBOOKING
The code is not tested. But.....
:)
Arun
==========================
Dim ss As New notessession
Dim ws As New notesuiworkspace
Dim targetdb As notesdatabase
Dim view As notesview
Dim uidoc As notesuidocument
Dim sourcedoc As notesdocument
Dim targetdoc As notesdocument
Dim sourcestarttime As Variant
Dim sourceendtime As Variant
Dim targetstarttime As Variant
Dim targetendtime As Variant
Dim sourcedate As Variant
Dim targetdate As Variant
Dim flag As String
Set uidoc = ws.Currentdocument
Set sourcedoc = uidoc.document
sourcestarttime = sourcedoc.STARTTIMEFIELDNA
sourceendtime = sourcedoc.ENDTIMEFIELDNAME
sourcedate = sourcedoc.DATEFIELDNAMEINY
Set targetdb = New notesdatabase(ss.CurrentDa
Set view = tardb.GetView("THEVIEWNAME
Set targetdoc = view.GetFirstDocument
flag = "Free"
Do While Not (targetdoc Is Nothing)
targetdate = targetdoc.DATEFIELDNAMEINY
targetstarttime = targetdoc.STARTTIMEFIELDNA
targetendtime = targetdoc.ENDTIMEFIELDNAME
If sourcedate = targetdate Then
If ((sourcestarttime >= targetstarttime And sourcestarttime <= targetendtime)) Or ((sourceendtime >= targetstarttime And sourceendtime <= targetendtime)) Then
Messagebox "A room is already booked in the specified timeslot "
Exit Do
End If
End If
Set targetdoc = view.GetNextDocument(targe
Loop
If flag = "Free" Then
Msgbox "No booking made to the room at the specified timeslot"
End If
==========================
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Arun,
Thanks for your code
Rajen
Thanks for your code
Rajen
ASKER