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
RajenAsked:
Who is Participating?
 
ArunkumarConnect With a Mentor Commented:
As above....
0
 
RajenAuthor Commented:
Edited text of question.
0
 
ArunkumarCommented:
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
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
RajenAuthor Commented:
Hi, Arun Can you send the code.
0
 
ArunkumarCommented:
Working on it.  You will get it in a couple of hours.

:)
Arun
0
 
ArunkumarCommented:
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
THEVIEWNAMEYOUWANTTOWALKTHROUGH ---  name of the view from which you were trying the GetDocumentByKey
STARTTIMEFIELDNAMEINYOURUIDOCUMENT --- start Time field name in your currentdocument
ENDTIMEFIELDNAMEINYOURUIDOCUMENT  ---  end time field name in your current document
STARTTIMEFIELDNAMEINYOURBOOKINGSDOCUMENT --- start time field name of the document that has to be checked
ENDTIMEFIELDNAMEINYOURBOOKINGSDOCUMENT  ---  end time field name of the document that has to be checked
DATEFIELDNAMEINYOURUIDOCUMENT  ---  date field in your current document
DATEFIELDNAMEINYOURBOOKINGSDOCUMENT  --- 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.STARTTIMEFIELDNAMEINYOURUIDOCUMENT(0)
     sourceendtime = sourcedoc.ENDTIMEFIELDNAMEINYOURUIDOCUMENT(0)
     sourcedate = sourcedoc.DATEFIELDNAMEINYOURUIDOCUMENT(0)
     
     Set targetdb = New notesdatabase(ss.CurrentDatabase.Server,"BOOKINGSDATABASENAME.nsf")
     Set view = tardb.GetView("THEVIEWNAMEYOUWANTTOWALKTHROUGH")          
     Set targetdoc = view.GetFirstDocument
     
     flag = "Free"
     
     Do While Not (targetdoc Is Nothing)
         
          targetdate = targetdoc.DATEFIELDNAMEINYOURBOOKINGSDOCUMENT(0)
         
          targetstarttime = targetdoc.STARTTIMEFIELDNAMEINYOURBOOKINGSDOCUMENT(0)
          targetendtime = targetdoc.ENDTIMEFIELDNAMEINYOURBOOKINGSDOCUMENT(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(targetdoc)
         
     Loop
     
     If flag = "Free" Then
         
          Msgbox "No booking made to the room at the specified timeslot"
         
     End If

====================================
0
 
RajenAuthor Commented:
Hi Arun,
Thanks for your code
Rajen
0
All Courses

From novice to tech pro — start learning today.