Solved

Document not saved when datefrom and dateto are same day

Posted on 2004-10-06
13
203 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:kopibean
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 19

Expert Comment

by:madheeswar
Comment Utility
the culprit is DayList field.

Check the formula of the field(default formula) and paste it here.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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
0
 
LVL 3

Expert Comment

by:Andrea Ercolino
Comment Utility
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
0
 

Author Comment

by:kopibean
Comment Utility
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
0
 
LVL 19

Expert Comment

by:madheeswar
Comment Utility
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
0
 
LVL 3

Expert Comment

by:Andrea Ercolino
Comment Utility
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.

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Expert Comment

by:Andrea Ercolino
Comment Utility
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
0
 
LVL 3

Expert Comment

by:Andrea Ercolino
Comment Utility
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 ) )


0
 

Author Comment

by:kopibean
Comment Utility
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
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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. ;)
0
 
LVL 3

Expert Comment

by:Andrea Ercolino
Comment Utility
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
0
 

Author Comment

by:kopibean
Comment Utility
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.
0
 
LVL 3

Accepted Solution

by:
Andrea Ercolino earned 50 total points
Comment Utility
Sorry for a late answer (I was on holyday)...

As I noted in a previous comment, your situation 2 is "correct", meaning that the code you have is coherent with that behaviour.

Now, if you want to get the behaviour you described in your last comment, you should ADD the following line

  newdoc(d).JActionDate_1 = doc.JActionDate_1

after the following line (ie. in the for loop)

  newdoc(d).JActionDate = Cdat(dlist(d+1))

--------------------------------
Also, I'd suggest that you implement something in the BookingForm2 for having the JActionDate and JActionDate_1 fields editable only if no registration occurred before, and not editable after a registration. This way, you can be sure that the user cannot mess things after a registration.

To implement this, you have to put each of your fields in a paragraph with a "hide when" formula set to

  NewRegister = "Registered"

Then you have to put in a new paragraph a computed for display field, one for each of your previous fields, for example named JAD for JActionDate and JAD_1 for JActionDate_1 , with the formulas set to

  in JAD:          JActionDate
  in JAD_1:       JActionDate_1

and in that paragraph, the "hide when" formula should be the opposite of the other, ie:

  NewRegister != "Registered"

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Recent Contacts - Lotus Notes 10 601
Email Message Background Color 4 113
Lotus notes email code 2 113
Migration Lotus to Exchange 2016 4 136
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now