Script Modification 2

Last Question for Today:

This script is from the sandbox conference room request database sample.It creates repeat documents for reservation requests.   How would I modify it to send an approval request mail with document link for each entry it creates to the designated approver?  Here is the script:

'RepeatEvent:

Option Public

Dim db As NotesDatabase
Dim doc As NotesDocument
Dim newdoc As NotesDocument
Dim startDate As NotesDateTime
Dim endDate As NotesDateTime
Dim answer As Integer
Dim interval As Integer
Sub RepeatEvent
      Dim session As New NotesSession
      Dim workspace As New NotesUIWorkspace
      
%REM
     If session.CommonUserName <> "Ken Feyder" Then
          Print "Functionality Not Yet Available"
          End
     End If
%END REM
      
      Set db = session.CurrentDatabase
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      
      REM 'answer = Messagebox("This process will save the current document and add new repeating events to the calendar.  Are you sure that you want to continue?", 36, "Continue?")
      REM 'If answer = 7 Then Exit Sub  'Get out if they anwer No to the message box.
      
      If Not(uidoc.EditMode) Then uidoc.EditMode = True
      Call uidoc.Save
      
     'check the date and time fields before allowing this entry to be repeated
      If doc.room(0) = "" Or doc.Date(0) = "" Or doc.TimeRange(0) = "" Or doc.MeetingTitle(0) = "" Or doc.Requester(0) = "" Then
            Messagebox "The Reservation Room, Date, Time, Description or Requester has not been entered.  This information must be entered to allow repeating functionality.", 16,_
            "Missing Information"
            End
      End If
      
     'Call the dialog box to get the repeat interval
      If workspace.DialogBox("DialogRepeatEntry", True, True, False, False, False, False, " Repeat Reservation Details") Then
          'Get the start date and end date
            Set startDate = New NotesDateTime(doc.Date(0))
            Set endDate = New NotesDateTime(doc.Until(0))
            
            'Set the Status
            doc.Status = "Submitted for Approval"
            
          'Find the interval
            Call FindInterval
            
          'Check dates
            If startDate.TimeDifference(endDate) > 0 Then
                  Messagebox "The First Repeating Date cannot come after the End Date.", 16, "Incorrect Dates"
                  End
            End If
            
          'Loop through dates until the end date and Make event entries
            Call RepeatLooping
            
          'Refresh the view/workspace
            Call uidoc.Save
            REM 'Call uidoc.Close Testing without this line
            Call workspace.ViewRefresh
      End If
End Sub
Sub FindInterval
      'Set the interval from the Repeat Unit
      Select Case doc.RepeatUnit(0)
      Case "D"
            interval = 1
            Call startdate.AdjustDay(interval)
      Case "W"
            interval = 7
            Call startdate.AdjustDay(interval)
      Case "BW"
            interval = 14
            Call startdate.AdjustDay(interval)
      Case "M"
            interval = 21
            Call startdate.AdjustDay(interval)
      Case "Y"
            interval = 28
            Call startdate.AdjustDay(interval)
      End Select
End Sub
Sub RepeatLooping
     'Repeat until we reach the end date.
      Do While startDate.TimeDifference(endDate) <= 0   'Once we check the end date we're done!!
          'Go make the document
            Call MakeDocument
            
          'Adjust date appropriately
            Select Case doc.RepeatUnit(0)
            Case "D", "W", "BW", "M", "Y"              
                  Call startdate.AdjustDay(interval)
            End Select
      Loop
End Sub
Sub MakeDocument
      Set newdoc = db.CreateDocument
      Call doc.CopyAllItems(newdoc, True)
      newdoc.DateCreated = Today
      newdoc.StartDate = startDate.LSLocalTime
      newdoc.Date = startDate.LSLocalTime
      newdoc.EventDate = startDate.LSLocalTime
      Call newdoc.Save(True, False)
      Print "Created new document for date " & Cstr(startDate.LSLocalTime)
End Sub

schmad01Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HemanthaKumarCommented:
I think MakeDocument will be appropriate for this

Sub MakeDocument
     Set newdoc = db.CreateDocument
     Call doc.CopyAllItems(newdoc, True)
     newdoc.DateCreated = Today
     newdoc.StartDate = startDate.LSLocalTime
     newdoc.Date = startDate.LSLocalTime
     newdoc.EventDate = startDate.LSLocalTime
     Call newdoc.Save(True, False)

set maildoc = db.CreateDocument
maildoc.Form = "memo"
maildoc.SendTo = doc.Approver(0) ' Here substitute with field name where it should send mail to
set rt = maildoc.CreateRichTextItem( "Body" )
Call rt.AppendText( "Here is the request..." )
call rt.AppendDocLink( newdoc, "Click to open" )
maildoc.Send false

     Print "Created new document for date " & Cstr(startDate.LSLocalTime)
End Sub


~Hemanth
0
HemanthaKumarCommented:
I missed to add subject line..


Sub MakeDocument
     Set newdoc = db.CreateDocument
     Call doc.CopyAllItems(newdoc, True)
     newdoc.DateCreated = Today
     newdoc.StartDate = startDate.LSLocalTime
     newdoc.Date = startDate.LSLocalTime
     newdoc.EventDate = startDate.LSLocalTime
     Call newdoc.Save(True, False)

set maildoc = db.CreateDocument
maildoc.Form = "memo"
maildoc.SendTo = doc.Approver(0) ' Here substitute with field name where it should send mail to
maildoc.Subject = "Conference room request for " & cstr(doc.Date(0)) & cstr(doc.Until(0))
set rt = maildoc.CreateRichTextItem( "Body" )
Call rt.AppendText( "Here is the request..." )
call rt.AppendDocLink( newdoc, "Click to open" )
maildoc.Send false

     Print "Created new document for date " & Cstr(startDate.LSLocalTime)
End Sub
0
qwaleteeCommented:
Hi schmad01,
> newdoc

I assume you want a single document with a list of links and their descriptions to go out, right?

Replace the existing Sub RepeatLooking.  You will haveto mdofiy it for the approver name.

Sub RepeatLooping
     CONST approverName = "Ken Feyder" 'or whatever E-Mail address to send the message to

     'Set up the approver message for later sending
     set approverMemo = db.CreateDocument
     approverMemo.Form = "Memo"
     approverMemo.SendTo = approverName
     approverMemo.Subject = "Repeat conference room booking: " & cstr(doc.Date(0)) & " to " & cstr(doc.Until(0))
     set rtf = approverMemo.CreateRichTextItem( "Body" )
     rtf.AppendText "Links to the repeat booking documents:"

     'Repeat until we reach the end date.
     Do While startDate.TimeDifference(endDate) <= 0   'Once we check the end date we're done!!
          'Go make the document
          Call MakeDocument
          rtf.AddNewLine 1
          rtf.AppendDocLink newdoc, cstr(startDate.lsLocalTime)
         
          'Adjust date appropriately
          Select Case doc.RepeatUnit(0)
          Case "D", "W", "BW", "M", "Y"              
               Call startdate.AdjustDay(interval)
          End Select
     Loop
     approverMemo.Send False
End Sub

Best regards,
qwaletee
0
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

schmad01Author Commented:
Heman,
Where would I put this Sub MakeDocument?

Qwal,
I tried yours and plugged my name into the approver spot.  I got the email with the multiple links, but the links pointed to the same document, not their respective documents.
0
schmad01Author Commented:
Heman,
Nevermind, duh, I see.  Let me try.
0
schmad01Author Commented:
I think I was wrong.  It looks like that in the Meeting Date fields, that it is not putting the right dates in. It leaves it with the first meeting date.
0
schmad01Author Commented:
I think I need a refresh for the docs after they are created.
0
schmad01Author Commented:
Because there is a computed date field that is not getting updated.
0
HemanthaKumarCommented:
In your script

          Set startDate = New NotesDateTime(doc.Date(0))
          Set endDate = New NotesDateTime(doc.Until(0))

Is refering to the Date and Until fields value.. If this is multivalued then you have to change the script to loop thru the values of these fields. So does this field have more than 1 value ?
0
HemanthaKumarCommented:
Sorry I misread it..
0
HemanthaKumarCommented:
Where is this computed field ? on ui form ? or on the reservation doc ?

Any default value formula ?
0
HemanthaKumarCommented:
If it is on newly created reservation document then in the MakeDocument function add Computewithform before save

Call newdoc.ComputeWithForm(true, false)
Call newdoc.Save(True, False)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
qwaleteeCommented:
Very odd tha the links all pointed to the same place.  Do the links have the same "comment" (he text in the properties box, which may also apear in the status bar message area when you hover over the link).  They shoudl each have a different date.

Try also changing the following:
          rtf.AppendDocLink newdoc, cstr(startDate.lsLocalTime)
to
          Dim summaryString as string
          summaryString = newDoc.noteID & " should start " & cstr(startDate.lsLocalTime) & " actually starts " & newdoc.startDate(0)
          rtf.AppendDocLink newdoc, summaryString
          rtf.AppendText " - " & summaryString
         


0
schmad01Author Commented:
Qwal,
I was wrong , they were pointing to the right documents. As stated above the dates did not get refreshed.  Heman solved that.

I have used a combination of both of your ideas so I will split the points.  Thanks alot.
0
schmad01Author Commented:
Thank you both alot.  More to come I'm sure. I'm learning a little about script every time you guys help.  
0
schmad01Author Commented:
OOPS! Found a problem:  Here is what is happening.
When a request is filled out and then set to repeat, the first day is not getting updated and the link is not included in the email.  For example, if I put in a request for a room for Dec. 15 thru Dec. 19, and hit submit, The document for Dec. 15th still says New as the Status when it should say Submitted for Approval. The repeat documents are ok however. And when the approver receives the request, the Dec. 15th doclink is not in the email but the repeat docs are.  Here is the full code as it stands now from both your inputs:

'RepeatEvent:

Option Public

Dim db As NotesDatabase
Dim doc As NotesDocument
Dim newdoc As NotesDocument
Dim startDate As NotesDateTime
Dim endDate As NotesDateTime
Dim answer As Integer
Dim interval As Integer
Sub RepeatEvent
      Dim session As New NotesSession
      Dim workspace As New NotesUIWorkspace
      
%REM
     If session.CommonUserName <> "Ken Feyder" Then
          Print "Functionality Not Yet Available"
          End
     End If
%END REM
      
      Set db = session.CurrentDatabase
      Set uidoc = workspace.CurrentDocument
      Set doc = uidoc.Document
      
      REM 'answer = Messagebox("This process will save the current document and add new repeating events to the calendar.  Are you sure that you want to continue?", 36, "Continue?")
      REM 'If answer = 7 Then Exit Sub  'Get out if they anwer No to the message box.
      
      If Not(uidoc.EditMode) Then uidoc.EditMode = True
      Call uidoc.Save
      
     'check the date and time fields before allowing this entry to be repeated
      If doc.room(0) = "" And doc.resource(0) = "" Or doc.Date(0) = "" Or doc.TimeRange(0) = "" Or doc.MeetingTitle(0) = "" Or doc.Requester(0) = "" Then
            Messagebox "The Reservation Room, Date, Time, Description or Requester has not been entered.  This information must be entered to allow repeating functionality.", 16,_
            "Missing Information"
            End
      End If
      
     'Call the dialog box to get the repeat interval
      If workspace.DialogBox("DialogRepeatEntry", True, True, False, False, False, False, " Repeat Reservation Details") Then
          'Get the start date and end date
            Set startDate = New NotesDateTime(doc.Date_1(0))
            Set endDate = New NotesDateTime(doc.Until(0))
            
            'Set the Status
            doc.Status = "Submitted for Approval"
            
            'Send Message
            Messagebox "Please click the Submit Button at the top of this form.", 16, "Document(s) created"
            
          'Find the interval
            Call FindInterval
            
          'Check dates
            If startDate.TimeDifference(endDate) > 0 Then
                  Messagebox "The First Repeating Date cannot come after the End Date.", 16, "Incorrect Dates"
                  End
            End If
            
          'Loop through dates until the end date and Make event entries
            Call RepeatLooping
            
          'Refresh the view/workspace
            Call uidoc.Save
            REM 'Call uidoc.Close Testing without this line
            Call workspace.ViewRefresh
      End If
End Sub
Sub FindInterval
      'Set the interval from the Repeat Unit
      Select Case doc.RepeatUnit(0)
      Case "D"
            interval = 1
            Call startdate.AdjustDay(interval)
      Case "W"
            interval = 7
            Call startdate.AdjustDay(interval)
      Case "BW"
            interval = 14
            Call startdate.AdjustDay(interval)
      Case "M"
            interval = 21
            Call startdate.AdjustDay(interval)
      Case "Y"
            interval = 28
            Call startdate.AdjustDay(interval)
      End Select
End Sub
Sub RepeatLooping
      Const approverName = "Marion Freeman" 'or whatever E-Mail address to send the message to
      
     'Set up the approver message for later sending
      Set approverMemo = db.CreateDocument
      approverMemo.Form = "Memo"
      approverMemo.SendTo = approverName
      approverMemo.Subject = "Repeat conference room booking: " & Cstr(doc.Date(0)) & " to " & Cstr(doc.Until(0))
      Set rtf = approverMemo.CreateRichTextItem( "Body" )
      rtf.AppendText "Links to the repeat booking documents:"
      
     'Repeat until we reach the end date.
      Do While startDate.TimeDifference(endDate) <= 0   'Once we check the end date we're done!!
          'Go make the document
            Call MakeDocument
            rtf.AddNewLine 1
            rtf.AppendDocLink newdoc, Cstr(startDate.lsLocalTime)
            
          'Adjust date appropriately
            Select Case doc.RepeatUnit(0)
            Case "D", "W", "BW", "M", "Y"              
                  Call startdate.AdjustDay(interval)
            End Select
      Loop
      approverMemo.Send False
End Sub
Sub MakeDocument
      Set newdoc = db.CreateDocument
      Call doc.CopyAllItems(newdoc, True)
      newdoc.DateCreated = Today
      newdoc.StartDate = startDate.LSLocalTime
      newdoc.Date = startDate.LSLocalTime
      newdoc.EventDate = startDate.LSLocalTime
      Call newdoc.ComputeWithForm(True, False)
      Call newdoc.Save(True, False)
      Call newdoc.Save(True, False)
      
      'Set maildoc = db.CreateDocument
      'maildoc.Form = "memo"
      'maildoc.SendTo = doc.receptionist(0) ' Here substitute with field name where it should send mail to
      'maildoc.Subject = "Conference room request for " & Cstr(doc.Date(0)) & Cstr(doc.Until(0))
      'Set rt = maildoc.CreateRichTextItem( "Body" )
      'Call rt.AppendText( "Here is the request..." )
      'Call rt.AppendDocLink( newdoc, "Click to open" )
      'maildoc.Send False
      
      Print "Created new document for date " & Cstr(startDate.LSLocalTime)
End Sub

0
qwaleteeCommented:
To get the link to the originating doc in change th following...

     Set rtf = approverMemo.CreateRichTextItem( "Body" )
     rtf.AppendText "Links to the repeat booking documents:"

... to ...

     Set rtf = approverMemo.CreateRichTextItem( "Body" )
     rtf.AppendText "Links to the initial document:"
     rtf.AppendDocLink doc
     rtf.AddNewLine 2
     rtf.AppendText "Links to the repeat booking documents:"
0
qwaleteeCommented:
As far as the status, I'm not sure.  The only thing I can think of is that "doc" which represents the back-end of the open document, is getting out of sync with the displayed form on screen.

The place where you change status to Submitted for APproval is within the big "If workspace.dialogBox" block of code.  That is the block of code that sets up all the repeats.  If the user cancels that dialog box, there is no repeat, AND the status will never be set to submitted for approval.  If the user does not cancel the dialog box, then the status is immediately changed on the back end.  That back end change is not immeidately saved.  Later in the block, there is a uiDoc.save.  The only thing (other than a code failure) that woudl prevent that uiDOc.save is:

          If startDate.TimeDifference(endDate) > 0 Then
               Messagebox "The First Repeating Date cannot come after the End Date.", 16, "Incorrect Dates"
               End
          End If

But that would also prevent creationof the repeats.

So, that's why I say it could be a uiDoc v. doc sync issue.  Try changing the following:
          'Refresh the view/workspace
          Call uidoc.Save
          REM 'Call uidoc.Close Testing without this line
... to ...
          'Refresh the view/workspace
          Call uidoc.reload
          Call uidoc.Save
          REM 'Call uidoc.Close Testing without this line

The reload is supposed to bring any doc changes back to uiDoc
0
schmad01Author Commented:
Ok,  I got the status to work.  Now the only thing is the number of links. All except the orignal doclinks are showing up.  I tried this replacement:

Set rtf = approverMemo.CreateRichTextItem( "Body" )
     rtf.AppendText "Links to the initial document:"
     rtf.AppendDocLink doc
     rtf.AddNewLine 2
     rtf.AppendText "Links to the repeat booking documents:"

as you stated above but got a Missing Argument message.
0
schmad01Author Commented:
And if this helps, when I go thru and approve all of these Dec. 15th thru the 19th they are supposed to show up in the calendar view.  They do, however the original document(Dec.15th) shows up in the Dec.19th block along with the Dec.19th document. Whoa.
0
qwaleteeCommented:
schmad01,
>      rtf.AppendDocLink doc
Sorry, s/b
     rtf.AppendDocLink doc , doc.StartDate(0)
0
schmad01Author Commented:
Got it .  That did it.  The original document was still appearing with the last document in the calendar.  I just put an entry in the approve button to set the date back in a hidden field that was getting changed for some reason. It works now.  Thanks qwal.  Anybody come up with ideas for my other pending question? :

http://www.experts-exchange.com/Applications/Email/Lotus_Notes/Q_20819577.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.