Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

Help creating a Nag Agent

I would like to create a Nag agent that will run daily to send an email to whoever is listed in the SendTo field of the document.

I have set up a view called "Nagview" which is correctly displaying a list of all the documents I wish to Nag about.
Now I need help with the agent which is to run through this view and send a document link to the relevant person along with an annoying message like "You have not updated this document for 30 days, please click the link below to do this now!"

Here is what I have written so far....am I going the right way here?
Any help towards this much appreciated!

Sub Initialize
      Dim ses As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      
      Set db= ses.CurrentDatabase
      Set view= db.GetView("Nagview")
      Set doc= view.GetFirstDocument
      Do Until doc Is Nothing
         Call doc.Send( False, [SendTo])
         Set doc= view.GetNextDocument(doc)
      Loop
End Sub
0
shuboarder
Asked:
shuboarder
2 Solutions
 
shuboarderAuthor Commented:
Sorry slight typo...

Sub Initialize
     Dim ses As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView
     Dim doc As NotesDocument
     
     Set db= ses.CurrentDatabase
     Set view= db.GetView("Nagview")
     Set doc= view.GetFirstDocument
     Do Until doc Is Nothing
        Call doc.Send( False, "SendTo")
        Set doc= view.GetNextDocument(doc)
     Loop
End Sub

I can set the SendTo to be myself, and I do receive lots of emails, but when I try and open the email I just get
"cannot locate form:"
0
 
Steve KnightIT ConsultancyCommented:
Try a

set doc.form="memo"

too

Steve
0
 
Steve KnightIT ConsultancyCommented:
Without the SET of course... doh!
doc.form="memo" befor you call doc.send

This is sending the document itself not a doclink though.
0
Independent Software Vendors: 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!

 
shuboarderAuthor Commented:
thanks for that Steve,

I had managed to figure that one out in time...

Here is the current non-working code:

Sub Initialize
      Dim ses As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim rtitem As NotesRichTextItem
      
      Set db= ses.CurrentDatabase
      Set view= db.GetView("Nagview")
      Set doc= view.GetFirstDocument
      Set rtitem = doc.NotesRichTextItem(doc, "Body")
      Do Until doc Is Nothing
            doc.form="memo"
            doc.subject="Document requires your attention"
            doc.body="You have not updated this document in the past 30 days, please do so now!"
            Call rtitem.AppendDocLink(doc, "Body")
            Call doc.Send( False, "SendTo")
            Set doc= view.GetNextDocument(doc)
      Loop
End Sub

any idea how I can include a doclink?
I am trying to do this using NotesRichTextItem above.
Is this the correct method?

Thanks
0
 
SysExpertCommented:
I would think that you need to docs, the original, and the one you want to send.
Use the copy all fields to transfer the fields over, and then just change just the fields needed, or look at the newsletter option to understand how to send doc links.

I hope this helps !
0
 
marilyngCommented:
Hee. hee.... I found that putting the subject: ESCALATION NOTICE!! in my "nag" e-mails resulted in an immediate response.  

However, you need to instantiate a maildoc in your loop:

Sub Initialize
     Dim ses As New NotesSession
     Dim db As NotesDatabase
     Dim view As NotesView
     Dim doc As NotesDocument
     Dim rtitem As NotesRichTextItem
     
     Set db= ses.CurrentDatabase
     Set view= db.GetView("Nagview")
     Set doc= view.GetFirstDocument
     While not doc is Nothing
        Dim maildoc as New NotesDocument (db)
         Set rtitem = New NotesRichTextItem(maildoc,"Body")
         maildoc.principal = "some.name"
         maildoc.from = "some.name"
         maildoc.subject = "ESCALATION NOTICE!! " + ="Document requires your attention"
         with rtItem
            .addnewline 1
            .appendText ="You have not updated this document in the past 30 days, please do so now!"
            .addNewLIne 1
            .appendDocLink doc, "Doc link to the document"
            .appendText "  << Click here to open the document"
            .addNewLine 1
         end with
          maildoc.sendTo = "somesendtoname"
          maildoc.send false
          set maildoc = nothing
          set rtItem = nothing
        set doc = view.getNextDocument(doc)
    wend

End Sub

Or something like that.. not tested.. :)  I always add ESCALATION NOTICE in red, and other options to the email.  Also, as sysExpert suggests .. and this is a bit more complicated, rather than spamming the nag notices, I usually step through a notes navigator and send a newsletter of all the links.

But this should get you started.  
0
 
Steve KnightIT ConsultancyCommented:
Missed the previous replies back there... agreed re: the newsletter type format, I tend to write it manually with more control over the layout and content of mails and sort the view by person then when stepping down it one mail is sent per person containing links to each of their docs but it depends upon the app.  In some apps it is unlikely there is more than one doc. per person in which case a mail per doc. is relatively acceptable.

Snippets of the code I use, this is based on a view sorted by person.  The way I do it is to use a fixed pitch font and then have a single column (3) in the view containing all the fields I want to show to the user and the column title for that column laid out with the titles to show, perhaps not the best way but meant one lot of code for multiple different reports.

Not meant as a complete solution for you, may give you some more ideas to work with too though.

Steve

View:   column1 = person name, sorted.  column2 = details to show in link, column3 = rest of line to show.

Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtitem As notesrichtextitem
Dim richStyle As NotesRichTextStyle
Dim view As notesview
Dim vc As notesviewentrycollection
Dim entry As notesviewentry
Dim sendto As Variant

Const viewname="TL_Report"
Const description="Team Leader"

' Create handle onto new document to send as email      
      Dim session As New notessession
      Set db=session.currentdatabase
      
' Check if on server
      If db.server="" Then
            Print "Scheduled script stopped on local database copy"
            End
      End If
      
' Create rich text style for amending boldness of type etc.
      Set richStyle = session.CreateRichTextStyle

set view=db.getview(viewname)
      
' Use dbcolumn to get list of unique names that need reporting to:
  Dim result As Variant
  result = Evaluate(|@unique(@trim(@DbColumn( "" : "NoCache" ; "" : "" ; "| & viewname & |" ; 1)))|)
      
'Step through list of users and send report for each:
  Forall user In result
    Print "Sending "& description & " report for " & user
    SendReport (user)
  End Forall

Sub SendReport(person As String)
      
'Create new document to send as 'newsletter'      
      Dim newsdoc As New notesdocument(db)
      Dim i As Long
      
'Search view for this person's entries
      Set vc= View .GetAllEntriesbyKey( person,True)
      
'Setup rich text parameters
      Set rtitem = New NotesRichTextItem( newsDoc, "Body")
      
'Start of message body
      richStyle.Bold = True
      richStyle.notesfont=FONT_HELV
      Call rtitem.AppendStyle(richStyle)
      Call rtitem.AppendText("Please review entries below.  You can click on the links next to each item to open each document.")
      Call rtitem.addnewline(2)
      
'Fixed pitch font, Heading Underlined, Blue
      richstyle.notesfont=FONT_COURIER      
      richstyle.notescolor=COLOR_DARK_BLUE
      richstyle.Bold=False
      richStyle.Underline= True
      Call rtitem.AppendStyle(richStyle)
      Call rtitem.AppendText("LINK" & "  " & View.columns(3).Title)
      
'Turn off underline, blue leaving in Courier font
      richStyle.Underline= False
      richstyle.notescolor=COLOR_BLACK
      Call rtitem.AppendStyle(richStyle)
      Call rtitem.addnewline(2)
      
'Iterate through filtered view and print line for each
      If vc.count<1 Then
            Call rtitem.AppendText("There are currently no matching documents for you.")
      Else
            For i=vc.count To 1 Step -1
                  Set entry=vc.getnthentry(i)
                  Call rtitem.AppendDocLink( entry.document, entry.columnvalues(2)) ' Doclink with hover details from view
                  Call rtitem.appendtext(Chr$(9) & entry.columnvalues(3)) ' pre-formatted report from view
                  Call rtitem.addnewline(1)
            Next
      End If
      
      newsDoc.Subject = "[Report] "& description & " review for "& person
      newsDoc.Form="Memo"
      newsdoc.SendTo=person
      
      Call newsdoc.Send(False)
      
End Sub
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now