Link to home
Start Free TrialLog in
Avatar of varvoura
varvoura

asked on

calendar

Hi all,

If possible, i would like to have a bit of help with the following:

The ability to prompt a user when they drag a calendar entry from one time slot to another with a prompt to ask if they would like to move all other entries related with this entry.
All entries related entries are within a multivalue date field which is populated in the calendar when the document is created.
For example, datefield will have:10/12/2005, 10/12/2006,  10/10/2006.......any many others and they are relating to the one product document.
If I decide to move 10/122005 by dragging it in the calendar view 3 days forward, then I want to be prompt whether or not I need to move the others too, if I answer "yes" then all other entries(in this case 2 other entries) will also move 3 days forward. If I answer no, then only this one entry which I have just dragged should move forward and others should stay the same.

Is this possible?
Avatar of varvoura
varvoura

ASKER

OK,

I have worked out the script for this, however, I am having a small problem with the first entry in the loop.

My loop does the following:

prompts the user if they want to change all other entries according with this change
if yes, then changes all the entries in the date field in accordance to the difference between the enddate and startdate of this change.

THE ONLY PROBLEM is:

It is also changing the current entry which is already changed, so the selected entry is changed twice and every other entry in the loop is changed OK.

Ideas??
Avatar of Steve Knight
Hmm, was thinking perhaps exclude any entries from your loop which is the new value already?  But then how does this handle it when you drag something that has entries for:

12-Jan
13-Jan
14-Jan

to 13-Jan though?  i.e. 12-Jan would move to 13-Jan, 13-Jan would then be ignored and 14-Jan would move to 15-Jan.

Can you post your current event handling code...

Steve
Ahh, how about:  Store a copy of the date field in your document as a calculated field, value as itself or hidden editable field.

In your event use this other field to add the difference of the other two dates to each element then write that back to your main field.  You'd have to update this field at any other time the main field can change too such as any submit or save buttons or other agents which manipulate the dates though.

Steve
Hi Steve,

Here's the code, I prefer that things are handled in the second forall loop that I have instead of creating other fields on the document, there's enough computed & hide when on that document to keep the world confused so if it can be done without additional form field it will be best.

Dim session As New NotesSession
      Dim db As notesdatabase
      Set db = session.currentdatabase
      
      Dim uiw As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Set uidoc = uiw.CurrentDocument
      Dim doc As NotesDocument
      Set doc = db.GetDocumentByID( source.CaretNoteID )
      
      
        Dim fromList As Variant
      Dim tmpList As Variant
      Dim toList As Variant
      Dim oldList() As String
      Dim newList As Variant
      Dim diff As Variant
      
      
      SelectedDate = uiw.CurrentCalendarDateTime
      
      fromDate = Cstr( Datevalue(uiw.CurrentCalendarDateTime ) )    
      toDate = Cstr( source.CalendarDateTime )
      
      fromDate = Left( fromDate, Len( fromDate) )
      toDate = Left( toDate, Len( toDate ))
      Dim date3 As Variant
      date3 = Cdat(todate) - Cdat(fromdate)
      
      tmpList =doc.docdatefield
      
      i=0
      
      Forall x In tmpList
            Redim Preserve oldList(i)
            oldList(i) = Format$(x, "Short Date")
            i = i + 1
      End Forall
      
      fromList = MakeArray( fromDate )
      toList = MakeArray( toDate )
      
      newList = Arrayreplace(oldList, fromList, toList )
      
      Dim askme As Integer
      askme = uiw.Prompt (PROMPT_YESNO, _
      "Test Schedule", "Would you like to move all other entries ?")
      
      Dim newlist1 As Variant
      newlist1 = newlist
      
      i = 0
      Forall x In newList1
            
            Redim Preserve newlist(i)
            If askme = 1 Then
                  
                  newlist(i) = Cdat(x) + date3
            Else
                  newlist(i)  = Cdat(x)
                  
            End If
            
            i = i+1
            
      End Forall
      
      doc.docdatefield= newList
      Call doc.Save( True, True, True )
      Call uiw.ViewRefresh
      
End Sub


I have also tried the following:

Created a selecteddate field where I picked up the document current time  and I tried in the loop to check with the value of x, if x <> selected value then newlist(i) = Cdat(x) + date3, Else newlist(i) = cdat(x), didn't work

I've also tried to place the following code in loop under just after the first line of the second forall statement:

I tried to compare x to todate to exclude that entry that matched todate from the loop or add only cdat(x) instead of cdat(x) + date3 to it.

So anyway at this stage both of my attempts were unsuccessful so I'd really appreciate your help if possible.

Thanks for your prompt responses
OK looks like you are replacing the old date with new then doing the move for the whole array again.  Best bet is to just do it once.  Something like this:

Apologies for any typos.

Steve



Dim session As New NotesSession
     Dim db As notesdatabase
     Set db = session.currentdatabase
     
     Dim uiw As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     Set uidoc = uiw.CurrentDocument
     Dim doc As NotesDocument
     Set doc = db.GetDocumentByID( source.CaretNoteID )
     
     
       Dim fromList As Variant
     Dim tmpList As Variant
     Dim toList As Variant
     Dim oldList() As String
     Dim newList As Variant
     Dim diff As Variant
     
     
     SelectedDate = uiw.CurrentCalendarDateTime
     
     fromDate = Cstr( Datevalue(uiw.CurrentCalendarDateTime ) )    
     toDate = Cstr( source.CalendarDateTime )
     
     fromDate = Left( fromDate, Len( fromDate) )
     toDate = Left( toDate, Len( toDate ))
     Dim date3 As Variant
     date3 = Cdat(todate) - Cdat(fromdate)
     
     tmpList =doc.docdatefield
     
     i=0
     
     Forall x In tmpList
          Redim Preserve oldList(i)
          oldList(i) = Format$(x, "Short Date")
          i = i + 1
     End Forall
     
     fromList = MakeArray( fromDate )
     toList = MakeArray( toDate )
     
     Dim askme As Integer
     askme = uiw.Prompt (PROMPT_YESNO, _
     "Test Schedule", "Would you like to move all other entries ?")

     Dim newlist1 As Variant
     if askme=1 then
         newlist1 = oldlist
         i = 0
         Forall x In newList1
            Redim Preserve newlist(i)
            newlist(i) = Cdat(x) + date3
            i = i+1
         End Forall
   else
      newList1 = Arrayreplace(oldList, fromList, toList )
         i = 0
         Forall x In newList1
            Redim Preserve newlist(i)
            newlist(i) = Cdat(x) + date3
            i = i+1
         End Forall

   end if
     
     doc.docdatefield= newList
     Call doc.Save( True, True, True )
     Call uiw.ViewRefresh
     
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Super, thank you Steve
No problem, thanks for the points.

Steve
My pleasure.

Vavoura