Solved

Code Update help

Posted on 2002-03-29
18
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 3
18 Comments
 
LVL 10

Expert Comment

by:zvonko
ID: 6910760
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
ID: 6912847
Nope,

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

Expert Comment

by:zvonko
ID: 6913682
which Notes release do you use?

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:schmad01
ID: 6913787
5.0.7a  from 4.6x
0
 
LVL 10

Expert Comment

by:zvonko
ID: 6913953
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
ID: 6913976
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
ID: 6914009
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
ID: 6914154
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
ID: 6925432
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
 
LVL 10

Expert Comment

by:zvonko
ID: 6926353
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
ID: 6926362
haa haa haa he is ferocious !!! I like to see that !

;-)
0
 
LVL 9

Expert Comment

by:Arunkumar
ID: 6926374
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
ID: 6926378
Arun, you are the first one calling afterwards my asking for honoring my invested time as begging :-)

0
 
LVL 9

Expert Comment

by:Arunkumar
ID: 6926387
<|:-)
0
 

Author Comment

by:schmad01
ID: 6929108
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
ID: 6929148
Yes, thanks.
I was all the day busy but now I start investigating...

0
 

Author Comment

by:schmad01
ID: 6931626
Thank you Thank you thank you.
0
 
LVL 10

Expert Comment

by:zvonko
ID: 6931672
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

763 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