David Schmalzer
asked on
Code Update help
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(server name,mailf ile)
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(Tru e,doc)
End Sub
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.
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(server
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(Tru
End Sub
ASKER
Nope,
Does not work. It says Document command is not available.
Does not work. It says Document command is not available.
which Notes release do you use?
ASKER
5.0.7a from 4.6x
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 :-)
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.
Instead of resolving your problem with this one extra line, you have another new problem with this error message. So remove my line again :-)
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.
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.
ASKER
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("EDCha nge", 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("StartDat e")
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(e nddate) > 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(e nddate) <= 0 'Once we check the end date we're done!!
flag = 0
days = Weekday(startdate.LSLocalT ime)
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
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("EDCha
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("StartDat
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(e
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(
Do While startdate.TimeDifference(e
flag = 0
days = Weekday(startdate.LSLocalT
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
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...
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...
ASKER
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.
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
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
haa haa haa he is ferocious !!! I like to see that !
;-)
;-)
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!
;-)
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!
;-)
Arun, you are the first one calling afterwards my asking for honoring my invested time as begging :-)
<|:-)
ASKER
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Thank you thank you.
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(Tru e,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.
<|:-)
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(Tru
Set doc = UIDoc.Document
doc.StartDate = CurDoc.StartDate(0)
doc.EndDate = CurDoc.EndDate(0)
Call uidoc.Reload
End Sub
That was all.
<|:-)
Call workspace.CurrentDocument.
That mean before this one:
Set CurDoc = workspace.CurrentDocument.
Good luck,
zvonko