Link to home
Start Free TrialLog in
Avatar of kopibean
kopibean

asked on

Document not saved when datefrom and dateto are same day

I have a form and on this form, there are several fields and among them, there are 2 date/time fields - JActionDate(Date from) and JActionDate_1(Date to).
Once user finish entering all the fields on the form and need to click on Register button to save this field.

Under the Register action button code :
Sub Click(Source As Button)
      Dim workspace As New NotesUIWorkspace
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Dim newdoc() As NotesDocument
      Dim uidoc As NotesUIDocument
      Dim user As String
      Dim actday As String
      Dim dateaa As String
      Dim j As Integer
      Dim d As Integer
      Dim dlist As Variant
      Dim docno As Integer
      Dim mem As Variant
      Dim mem2 As Variant
      Dim reqst As String
      Dim region As String
      Dim deptid As String
      Dim mach As String
      Dim purp As String
      
      Set db = session.CurrentDatabase
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      Call uidoc.Refresh
      
      user = session.CommonUserName
      actday = doc.JActionDate(0)
      reqst = doc.RequestorN(0)
      region = doc.RegionA(0)
      deptid = doc.DepartmentD(0)
      mach = doc.MachineR(0)
      purp = doc.Purpose(0)
      mem = doc.MEMBERS
      mem2 = doc.member
      dateaa = doc.date1(0)
      dlist = doc.DayList
      
      If doc.NewRegister(0) = "Registered" Then
            Messagebox "This schedule had already registered, no registration is needed any more, please just save the document.",1+16,"Save Please!"
            continue = False
            Exit Sub
      End If
      
      
      mes = {
           Click OK to create range of schedule with same contents of this document.
           If need any changes in individual item, please amend later.
                                 
                     Your designated date range is correct? then click OK!
}
      
      
      answer = Messagebox (mes,1+32,"Hello!  " & user & "-san")
      
      docno = Ubound(dlist)-1
      
      Redim newdoc(docno)
      
      For d = 0 To docno
            Set newdoc(d) = db.CreateDocument
            newdoc(d).Form = "BookingForm2"
            newdoc(d).RequestorN = reqst
            newdoc(d).RegionA = region
            newdoc(d).DepartmentD = deptid
            newdoc(d).MachineR = mach
            newdoc(d).Purpose = purp
            newdoc(d).date1 = dateaa
            newdoc(d).MEMBERS = mem
            newdoc(d).member = mem2
            newdoc(d).JActionDate = Cdat(dlist(d+1))  
            newdoc(d).NewRegister = "Registered"
            newdoc(d).notice = "NotYet"
            Call newdoc(d).Save(False,False)
      Next
      
      
      Call uidoc.FieldSetText("NewRegister","Registered")
      Call uidoc.Save
      Call uidoc.Close
      
End Sub

Situation 1:
When I click the Register button to save the form selecting the JActionDate on 10/06/2004 and JActionDate_1 on 10/06/2004, it gives me an error ->Subscript out of range. I run lotuscript debugger and is on this line ->Redim newdoc(docno)
Anywhere gone wrong?
Pls advise

Situation 2:
Also, when different dates are select on these 2 date/time fields, e.g. 10/06/2004 on JActionDate and 10/11/2004 on JActionDate_1 in document A, document A is saved but in a calendar view, when i click on the document A under date 10/07/2004, JActionDate is shown as 10/07/2004 and JActionDate_1 is shown as 10/06/2004 on the form and when i click on the same document A under date 10/08/2004, JActionDate is shown as 10/08/2004 and JActionDate_1 is shown as 10/06/2004 on the form.
Anywhere gone wrong??
Pls advise.

Pls advise the above 2 situation
Avatar of madheeswar
madheeswar
Flag of Singapore image

the culprit is DayList field.

Check the formula of the field(default formula) and paste it here.
Avatar of Sjef Bosman
Some remarks:
- if Ubound(daylist) is 0, then you do a redim with -1 !
- what is the daylist for?
- I think you mean
    Redim Preserve (daylist)
- I also think you meant to extend the array, so not Ubound(daylist)-1 but +1
Avatar of Andrea Ercolino
Andrea Ercolino

Ohayo kopibean.

1
I think the problem is that docno should be Ubound( dlist ), not Ubound( dlist ) - 1. In fact, if you have the same date, then dlist contains only 1 element and it is in the 0th position, so Ubound( dlist ) would be 0, and the redim fails because you try to change the size of the newdoc array to -1.

2
I'm sorry, but here I'm a little confused... It seems like you changed JActionDate_1 to something different in the script, because I couldn't find where the newdoc has this field set. Maybe the form "BookingForm2" has a Computed for Display field JActionDate_1, whose formula could be enlightning.

matane
Avatar of kopibean

ASKER

madheeswar ,
Daylist field formula is ->
@If(Duration="";"";@Explode(Duration))

sjef_bosman  ,
I'm not sure what the daylist is for as i'm amending previous designer db

 RAPUTA,
JActionDate_1 is not in the script in the first place. I did not change to something different.
It is an editable Date/Time field with default value @Today

Please advise.
Thank you
then display the formula for Duration field.

Your Ubound is not getting values. Thats why you get error. U need to change the code a little bit.

change here:
If ubound(dlist)>0 then
docno = Ubound(dlist)-1
else
docno = Ubound(dlist)
endif
     
     Redim newdoc(docno)
     
     For d = 0 To docno
          Set newdoc(d) = db.CreateDocument
          newdoc(d).Form = "BookingForm2"
          newdoc(d).RequestorN = reqst
          newdoc(d).RegionA = region
          newdoc(d).DepartmentD = deptid
          newdoc(d).MachineR = mach
          newdoc(d).Purpose = purp
          newdoc(d).date1 = dateaa
          newdoc(d).MEMBERS = mem
          newdoc(d).member = mem2
          newdoc(d).JActionDate = Cdat(dlist(d+1))  
          newdoc(d).NewRegister = "Registered"
          newdoc(d).notice = "NotYet"
          Call newdoc(d).Save(False,False)
     Next
OK, I think it's time to make things clear.

--a
when you register with two different dates for JActionDate and JActionDate_1, I'm quite sure you get 1 document less than you should in the calendar view. Maybe I'm wrong, but your first script shows that you create one document less than the number of days between both dates inclusive.

--b
if you want to preserve the current logic of your script and get rid of the error in case of same date, you should use this code:
...
  docno = Ubound( dlist ) - 1

  if docno >= 0 then
    Redim newdoc( docno )
    For d = 0 To docno
...
    Next
  end if

    Call uidoc.FieldSetText("NewRegister","Registered")
    Call uidoc.Save
    Call uidoc.Close
End Sub

--c
point 2 of your question, now knowing that JActionDate_1 is an editable field with a default value set to @Today, is the correct behaviour. In fact, if a document does not have a field, then when you visualize the document by a form which in turn has the field, the value shown will be the default one. So whenever you open a document created through the Register action script, and the script does not set the JActionDate_1 field for any document of the newdoc array, you will see the date of today in the field.

A comment on my previous point --b

I was a little wrong. The current logic of your script is "Create as many new documents as the number of days between JActionDate and JActionDate_1, including the day in JActionDate but excluding the day in JActionDate_1"

Now, if you have JActionDate = JActionDate_1, your script trigs an error and this a very good thing for you, because you have the opportunity to extend the logic in a way such that this special case is treated as well.

So you DO have to decide wether a document has to be created in the special case or not. In my point --b I supposed the latter. For the former, the code is
...
  docno = Ubound( dlist ) - 1

  if docno >= 0 then
    Redim newdoc( docno )
    For d = 0 To docno
      Set newdoc(d) = db.CreateDocument
      newdoc(d).Form = "BookingForm2"
      newdoc(d).RequestorN = reqst
      newdoc(d).RegionA = region
      newdoc(d).DepartmentD = deptid
      newdoc(d).MachineR = mach
      newdoc(d).Purpose = purp
      newdoc(d).date1 = dateaa
      newdoc(d).MEMBERS = mem
      newdoc(d).member = mem2
      newdoc(d).JActionDate = Cdat( dlist( d+1 ) )
      newdoc(d).NewRegister = "Registered"
      newdoc(d).notice = "NotYet"
      Call newdoc(d).Save( False, False )
    Next
  else
    Redim newdoc( 0 )
    d = 0
    Set newdoc(d) = db.CreateDocument
    newdoc(d).Form = "BookingForm2"
    newdoc(d).RequestorN = reqst
    newdoc(d).RegionA = region
    newdoc(d).DepartmentD = deptid
    newdoc(d).MachineR = mach
    newdoc(d).Purpose = purp
    newdoc(d).date1 = dateaa
    newdoc(d).MEMBERS = mem
    newdoc(d).member = mem2
    newdoc(d).JActionDate = Cdat( dlist( d ) )    'this line is different
    newdoc(d).NewRegister = "Registered"
    newdoc(d).notice = "NotYet"
    Call newdoc(d).Save( False, False )
  end if

    Call uidoc.FieldSetText("NewRegister","Registered")
    Call uidoc.Save
    Call uidoc.Close
End Sub
Looking deeper at your original script, I think you have to use my previous script adjustment, ie you have to register at least one document

Even if your script follows the logic I described earlier, weirdly enough it finally creates documents from JActionDate excluded to JActionDate_1 included, because of the assignment
  newdoc(d).JActionDate = Cdat( dlist( d+1 ) )


madheeswar ,
I try your code but I can't save my form?
Any code I need to add in?
Pls advise.

RAPUTA,
I try this code->
docno = Ubound( dlist ) - 1

  if docno >= 0 then
    Redim newdoc( docno )
    For d = 0 To docno
...
    Next
  end if

    Call uidoc.FieldSetText("NewRegister","Registered")
    Call uidoc.Save
    Call uidoc.Close
End Sub
 
but there are some errors.

On your 2nd code,if the date is the same, it register 2 times in the database. If the date are not the same, it can register but the problem on my situation 2 is not solved.

Pls advise.
Thanks
Please show us the original code, and tell us what you want to be changed. I think we're guessing wrong all the time, for there is only some unformation available. ;)
So we now know that your first form (the form where the register button is placed) is also "BookingForm2".
This means that you should use my first script, because the current document is always "registered" and creation of new documents is needed only if the dates are different.

The right code is the following (and if it worked before, except in the special case of same date, it must work now):

Sub Click(Source As Button)
     Dim workspace As New NotesUIWorkspace
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim doc As NotesDocument
     Dim newdoc() As NotesDocument
     Dim uidoc As NotesUIDocument
     Dim user As String
     Dim actday As String
     Dim dateaa As String
     Dim j As Integer
     Dim d As Integer
     Dim dlist As Variant
     Dim docno As Integer
     Dim mem As Variant
     Dim mem2 As Variant
     Dim reqst As String
     Dim region As String
     Dim deptid As String
     Dim mach As String
     Dim purp As String
     
     Set db = session.CurrentDatabase
     Set uidoc = workspace.CurrentDocument
     Set doc = uidoc.Document
     Call uidoc.Refresh
     
     user = session.CommonUserName
     actday = doc.JActionDate(0)
     reqst = doc.RequestorN(0)
     region = doc.RegionA(0)
     deptid = doc.DepartmentD(0)
     mach = doc.MachineR(0)
     purp = doc.Purpose(0)
     mem = doc.MEMBERS
     mem2 = doc.member
     dateaa = doc.date1(0)
     dlist = doc.DayList
     
     If doc.NewRegister(0) = "Registered" Then
          Messagebox "This schedule had already registered, no registration is needed any more, please just save the document.",1+16,"Save Please!"
          continue = False
          Exit Sub
     End If
     
     
     mes = {
           Click OK to create range of schedule with same contents of this document.
           If need any changes in individual item, please amend later.
                                 
                     Your designated date range is correct? then click OK!
}
     
     
     answer = Messagebox (mes,1+32,"Hello!  " & user & "-san")
     
  if answer <> IDOK then exit sub

     docno = Ubound(dlist)-1
     
  if docno >= 0 then

     Redim newdoc(docno)
     
     For d = 0 To docno
          Set newdoc(d) = db.CreateDocument
          newdoc(d).Form = "BookingForm2"
          newdoc(d).RequestorN = reqst
          newdoc(d).RegionA = region
          newdoc(d).DepartmentD = deptid
          newdoc(d).MachineR = mach
          newdoc(d).Purpose = purp
          newdoc(d).date1 = dateaa
          newdoc(d).MEMBERS = mem
          newdoc(d).member = mem2
          newdoc(d).JActionDate = Cdat(dlist(d+1))  
          newdoc(d).NewRegister = "Registered"
          newdoc(d).notice = "NotYet"
          Call newdoc(d).Save(False,False)
     Next
     
  end if

     Call uidoc.FieldSetText("NewRegister","Registered")
     Call uidoc.Save
     Call uidoc.Close
     
End Sub
sjef_bosman and RAPUTA,
i am using RAPUTA code and it is working for same date and different dates(is able to register to the database)except in situation 2,
when I select different dates on these 2 date/time fields, e.g. 10/06/2004 on JActionDate and 10/11/2004 on JActionDate_1 in document A, document A is saved but in a calendar view, when i click on the document A under date 10/07/2004, JActionDate is shown as 10/07/2004 and JActionDate_1 is shown as 10/06/2004 on the form and when i click on the same document A under date 10/08/2004, JActionDate is shown as 10/08/2004 and JActionDate_1 is shown as 10/06/2004 on the form.

The correct format shoud be when I click on the document under 10/07/2004, JActionDate is shown as 10/07/2004 and JActionDate_1 is shown as 10/11/2004 on the form and under date 10/08/2004, JActionDate is shown as 10/08/2004 and JActionDate_1 is shown as 10/11/2004 on the form
Anywhere gone wrong??
Pls advise.
ASKER CERTIFIED SOLUTION
Avatar of Andrea Ercolino
Andrea Ercolino

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