Solved

Script Modification 2

Posted on 2003-12-09
22
315 Views
Last Modified: 2013-12-18
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

0
Comment
Question by:schmad01
  • 11
  • 6
  • 5
22 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
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
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
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
 
LVL 31

Assisted Solution

by:qwaletee
qwaletee earned 250 total points
Comment Utility
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
 

Author Comment

by:schmad01
Comment Utility
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
 

Author Comment

by:schmad01
Comment Utility
Heman,
Nevermind, duh, I see.  Let me try.
0
 

Author Comment

by:schmad01
Comment Utility
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
 

Author Comment

by:schmad01
Comment Utility
I think I need a refresh for the docs after they are created.
0
 

Author Comment

by:schmad01
Comment Utility
Because there is a computed date field that is not getting updated.
0
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
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
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
Sorry I misread it..
0
 
LVL 24

Expert Comment

by:HemanthaKumar
Comment Utility
Where is this computed field ? on ui form ? or on the reservation doc ?

Any default value formula ?
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 24

Accepted Solution

by:
HemanthaKumar earned 250 total points
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 

Author Comment

by:schmad01
Comment Utility
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
 

Author Comment

by:schmad01
Comment Utility
Thank you both alot.  More to come I'm sure. I'm learning a little about script every time you guys help.  
0
 

Author Comment

by:schmad01
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 

Author Comment

by:schmad01
Comment Utility
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
 

Author Comment

by:schmad01
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
schmad01,
>      rtf.AppendDocLink doc
Sorry, s/b
     rtf.AppendDocLink doc , doc.StartDate(0)
0
 

Author Comment

by:schmad01
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

14 Experts available now in Live!

Get 1:1 Help Now