Solved

Code Update help

Posted on 2002-03-29
18
183 Views
Last Modified: 2013-12-18
I have a script in a vacation database which in Notes 4.6 would populate the users calendar with the dates.  Now since we have been upgraded to Notes 5.07, the script does not work correctly.  Instead of putting the dates entered , it puts in today's date. I upped the points to 70.  Here is the code:

Sub Click(Source As Button)
     Dim session As New NotesSession
     Dim workspace As New NotesUIWorkspace
     Dim Doc As NotesDocument
     Dim db As NotesDatabase
     Dim UIDoc As NotesUIDocument
     Dim CurDoc As NotesDocument
     Dim servername As String
     Dim user As String
     Dim reg As New NotesRegistration
     Dim regserver As String
     Dim mailserver As String
     Dim mailfile As String
     Dim maildomain As String
     Dim mailsystem As Integer
     Dim profile As String
     
     Set CurDoc = workspace.CurrentDocument.Document
     Set db = session.CurrentDatabase
     servername = db.Server
     user = session.CommonUserName
     reg.RegistrationServer = servername
     
     Call reg.getUserInfo(user, mailserver, mailfile,  maildomain, mailsystem, profile)
     
     Set db = session.GetDatabase(servername,mailfile)
     Set doc = db.CreateDocument
     doc.form = "Appointment"
     doc.AppointmentType = "2"
     doc.Subject = CurDoc.ReqType(0) & "--" & CurDoc.Name(0) & ". (Approved by " &  CurDoc.Manager(0) & ") "
     doc.StartDate = CurDoc.StartDate(0)
     doc.Duration = CurDoc.CalDays(0)
     doc.ExcludeFromView = "D"
     Set UIDoc = Workspace.EditDocument(True,doc)
End Sub
0
Comment
Question by:schmad01
  • 9
  • 6
  • 3
18 Comments
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
Insert this statement as first executable statement:
Call workspace.CurrentDocument.Refresh

That mean before this one:
Set CurDoc = workspace.CurrentDocument.Document

Good luck,
zvonko
0
 

Author Comment

by:schmad01
Comment Utility
Nope,

Does not work.  It says Document command is not available.
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
which Notes release do you use?

0
 

Author Comment

by:schmad01
Comment Utility
5.0.7a  from 4.6x
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
Sorry, you said this in your question :-)

Really, I have tested the code in my Designer.
This one extra first statement does enforce a Form recalculation.
Normally this recalculation is not needed. But as I understand your question, you have two fields on your form which you like to use for the new document.
In R4.6 was the content of this two fields is correctly read and transferred to the new document. In the new version you get the content, but the wrong one.
I mean this two assignments are the problem:
doc.StartDate = CurDoc.StartDate(0)
doc.Duration = CurDoc.CalDays(0)

So my proposal was to enforce a front-end Form recalculation and then catch the Backend document.

Normally after this statement:
Dim workspace As New NotesUIWorkspace
you have an usable "workspace" object. And you can immediately call this method:
Call workspace.CurrentDocument.Refresh

Instead of resolving your problem with this one extra line, you have another new problem with this error message. So remove my line again :-)

0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
I have now your error message :-)

It arise when your button is on a document that is in read mode :-)

Switch to edit mode (for example by pressing CTRL-E ) and the error will not occure.

0
 

Author Comment

by:schmad01
Comment Utility
Yes, I discovered that, too but it still did not put the correct dates in.  Here is the code for CalculateDays.  Maybe the problem is in there somewhere?

Sub CalculateDays
     Dim session As New NotesSession
     Dim workspace As New NotesUIWorkspace
     Dim doc As NotesDocument
     Dim uidoc As NotesUIDocument
     Dim startdate As NotesDateTime
     Dim enddate As NotesDateTime
     Dim startitem As NotesItem
     Dim enditem As NotesItem
     Dim counter As Integer
     Dim flag As Integer
     Dim days As Integer
     'Few new dims
     Dim hookdoc As NotesDocument
     Dim hookview As NotesView
     Dim db As NotesDatabase
     Dim duration() As String
     
     Set db = session.CurrentDatabase
     Set uidoc = workspace.CurrentDocument
     Set doc = uidoc.Document
     If workspace.DialogBox("EDChange", True, True, False, False, False, False, "Please Select the Beginning and Ending Dates.") Then
          doc.Counter = 2
         
          'if either field is empty don't do calculations and blank out days field.
          If doc.StartDate(0) = "" Or doc.EndDate(0) = "" Then
               doc.TotalDays = ""
               End
          End If
          Set startitem = doc.GetFirstItem("StartDate")
          Set startdate = startitem.DateTimeValue
          Set enditem = doc.GetFirstItem("EndDate")
          Set enddate = enditem.DateTimeValue
          counter = 0
         
          'Make sure that the start date is before the end date
          If startdate.TimeDifference(enddate) > 0 Then
               Messagebox "The Start Date cannot come after the End Date.", 16, "Incorrect Dates"
               Call uidoc.GoToField("StartDate")
               End
          End If
         
          'Get the list of Holidays
          Set hookview = db.GetView("Holidays")
          Set hookdoc = hookview.GetDocumentByKey("Holidays",True)
         
         
          Do While startdate.TimeDifference(enddate) <= 0   'Once we check the end date we're done!!
               flag = 0
               days = Weekday(startdate.LSLocalTime)
               If days <> 1 And days <> 7 Then
                    'check for holidays
                    Forall holiday In hookdoc.AllHolidays
                         If Cdat(holiday) = startdate.LSLocalTime Then flag=1
                    End Forall
                   
                    If flag =0 Then
                         Redim Preserve duration(0 To counter)
                         duration(counter) = startdate.LSLocalTime
                         counter = counter +1
                    End If
               End If
               Call startdate.AdjustDay(1)
          Loop
          doc.TotalDays = counter
          doc.Duration = duration
          Call uidoc.Refresh
     End If
End Sub
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
no, both items are not changed anywhere in "CalculateDays"

You fetch this two items in your populate button code:
doc.StartDate = CurDoc.StartDate(0)
doc.Duration = CurDoc.CalDays(0)

CalculateDays only reads the "StartDate" and even do not touch "CalDays" item.

So, look on your form in design what the DefaultValue formulas for the upper two items are. Or even better: before clicking on the populate button, invoke the property dialog and look into document items. Perhaps are the fields you see on the form different one than those you fetch in your button code...

0
 

Author Comment

by:schmad01
Comment Utility
Is there any Lotus Notes 5 experts out there?  In response to zvonko's last question the first field is just what it says it is the start date of the requested vacation. CalDays is a hidden computed field that just calculates the duration between StartDate and EndDate.
0
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

 
LVL 10

Expert Comment

by:zvonko
Comment Utility
And I responded to you that this wrong Dates come from wrong initialization.
How should I investigate this from remote?

Send me this dammed nsf and I will fix it for you.

Zip it and send to: zp@arcor.de

0
 
LVL 9

Expert Comment

by:Arunkumar
Comment Utility
haa haa haa he is ferocious !!! I like to see that !

;-)
0
 
LVL 9

Expert Comment

by:Arunkumar
Comment Utility
Hi  schmad01,

Try doc.ComputeWithForm in your first code (Check help for further information).  This will compute all the values of the computed fields.  Make sure that you have the formula as the computed value.

This code may go before you edit the document okay ?

Easy Buddy!

Hi Zvo!
;-)
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
Arun, you are the first one calling afterwards my asking for honoring my invested time as begging :-)

0
 
LVL 9

Expert Comment

by:Arunkumar
Comment Utility
<|:-)
0
 

Author Comment

by:schmad01
Comment Utility
I sent the database zipped to zvonko since he was first. I didn't try Arun's suggestion because I am not that familiar with script. Zvonko, did you get the file?
0
 
LVL 10

Accepted Solution

by:
zvonko earned 90 total points
Comment Utility
Yes, thanks.
I was all the day busy but now I start investigating...

0
 

Author Comment

by:schmad01
Comment Utility
Thank you Thank you thank you.
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
You are welcome.

Anytime again.

And here to make people hapy who buy this solution the text from my email to schmad01:
"It was good that I have looked into your database because I would all the time assume it is something special on your installation. Now I have seen it is a general Lotus mail template problem. For any reasons (but mainly for web support script libraries) has the behavior of mail template changed. It is impossible to set the StartDate and then open UIDOC. It is always overwritten by the actual date.

My solution for this is to additional overwrite this recalculated StartDate by the original one from the source document. That mean, you have to add four lines at the end of PopulateNotesCalendar action.
Finally the action looks like this:
 Set UIDoc = Workspace.EditDocument(True,doc) 'this was your last line
 Set doc = UIDoc.Document
 doc.StartDate = CurDoc.StartDate(0)
 doc.EndDate = CurDoc.EndDate(0)
 Call uidoc.Reload
End Sub


That was all.

<|:-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
Notes Document Link used by IBM Notes is a link file which aids in the sharing of links to documents in email and webpages. The posts describe the importance and steps to create a Lotus Notes NDL file in brief.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now