Link to home
Start Free TrialLog in
Avatar of pratigan
pratiganFlag for United States of America

asked on

Display While running a Manual Agent

Hello,
I have an agent that sends an email to everyone from a view that has a document still in open status over 5 days.  The script is below.  I'd like to add a display in the agnet so that when I initiate it, I can see a progress bar and total.
TY
paul

Option Public

Sub Initialize
      Dim session As notessession
      Dim doc As notesdocument
      Dim curdoc As notesdocument
      Dim db As notesdatabase
      Dim v As NotesView
      Dim rtitem As NotesRichTextItem
      Dim item As NotesItem
      
      Set session = New notessession
      Set db = session.Currentdatabase
      Set doc = New notesdocument (db)
      Set v = db.GetView( "OpenIRs5")
      
      Set curdoc = v.GetFirstDocument
      Do Until curdoc Is Nothing
            Dim tmpArr() As String
            Dim i As Integer
            
            Set item = curdoc.GetFirstItem( "assigned" )   'instead of Forall loop
            item.IsNames= True
            Call doc.CopyItem( item, "SendTo" )
            
      '      doc.sendto=curdoc.assigned
            doc.principal= "eStar Open IR Auto Notification Monitor"
            doc.Subject = "Assigned IR over 5 days old Pending Your Review."
            doc.Remark = "This notification is autogenerated.  Please do not reply to this email."
            Set rtitem = New NotesRichTextItem( doc, "Body" )
            Call rtitem.AppendText( "This is a Daily Notification Process indicating you have an open IR older than 5 days that Requires your attention. " + Chr(13) + "Please Open, Review and Update the IR." + Chr(13) + "A Final Cause and Resolution are Required. " + Chr(13) + "Thank You !" + Chr(13) + "Open IR Document Link  ->  " )
            Call rtitem.AppendDocLink( curdoc, doc.Subject( 0 ) )
            'Call doc.send(False,curdoc.assigned)
            
            Call doc.Send( False )
            
            Set curdoc = v.GetNextDocument( curdoc )
      Loop
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Sam654
Sam654
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if you can guarantee the agent will be run on a windows platform, you can use code as detailed in http://searchdomino.techtarget.com/tip/Leverage-the-progress-bar-within-Notes
Avatar of Sjef Bosman
If the Print is ok with you, you usually don't need a print of every document. Instead, you could use

      If progress Modulo 100 = 0 Then

or something like that.
Avatar of pratigan

ASKER

ok... Print I guess is fine with me.  I just want to be able to see where the progress is cause sometimes theres a wrong email address which causes the progress to stop.  If I had a progress meter I would see where it stopped.  Not a big deal to display the wrong email, but would be nice to see a progress meter.
So going with the print statements I'm going to set a variable and counter
Dim totalcount As variable
Dim counter as numeric
Set count = 0
then inside the loop under the Call doc.Send( False ) I would put
progress = progress +1
Call Print "Processed " + Cstr( progress ) + " of " + Cstr( totalCount ) + " documents."
??
I have setup my DIM statements and the SET command is giving me may only be used on class assignments.  (?)  on print getting unexpected print; expected identified (?)
I have this so far:
ption Public

Sub Initialize
      Dim session As notessession
      Dim doc As notesdocument
      Dim curdoc As notesdocument
      Dim db As notesdatabase
      Dim v As NotesView
      Dim rtitem As NotesRichTextItem
      Dim item As NotesItem
      Dim totalcount As variant
      Dim counter As integer
      
      
      Set session = New notessession
      Set db = session.Currentdatabase
      Set doc = New notesdocument (db)
      Set v = db.GetView( "OpenIRs5")
      Set counter = 0
      
      
      Set curdoc = v.GetFirstDocument
      Do Until curdoc Is Nothing
            Dim tmpArr() As String
            Dim i As Integer
            
            Set item = curdoc.GetFirstItem( "assigned" )   'instead of Forall loop
            item.IsNames= True
            Call doc.CopyItem( item, "SendTo" )
            
      '      doc.sendto=curdoc.assigned
            doc.principal= "eStar Open IR Auto Notification Monitor"
            doc.Subject = "Assigned IR over 5 days old Pending Your Review."
            doc.Remark = "This notification is autogenerated.  Please do not reply to this email."
            Set rtitem = New NotesRichTextItem( doc, "Body" )
            Call rtitem.AppendText( "This is a Daily Notification Process indicating you have an open IR older than 5 days that Requires your attention. " + Chr(13) + "Please Open, Review and Update the IR." + Chr(13) + Chr(13) + "A Final Root Cause and Resolution are Required. " + Chr(13) + Chr(13) + "Thank You !" + Chr(13) + Chr(13) + "Open IR Document Link  ->  " )
            Call rtitem.AppendDocLink( curdoc, doc.Subject( 0 ) )
            'Call doc.send(False,curdoc.assigned)
            
            Call doc.Send( False )
            counter = counter +1
            Call Print "Processed " + CStr( counter ) + " of " + CStr( totalCount ) + " documents."
            
            
            Set curdoc = v.GetNextDocument( curdoc )
      Loop
End Sub
new statements added are counter, totalcount and print call.
ok.. I realized the print needed a qualifier so I added:
 Dim uidoc As NotesUIDocument
  Set uidoc = workspace.CurrentDocument

and then changed the print to:
Call uidoc.Print ("Processed " + CStr( counter ) + " of " + CStr( totalCount ) + " documents.")
            
but i still have the Set counter problem.  Also how do I set the totalcount value ?
Thank You !
Set is only to be used for objects. Your variable 'counter' is not an object, so a mere 'counter = 0' suffices.
Totalcount you can get from the total number of entries in the view.
The compiler would warn him for that if he would heed the Domino Developer Best Practices and always have Option Declare or Option Explicit in his code.
Note that setting the property to do this in Domino Designer forgets to set the Option Declare everywhere when needed, like for example in the form part or actions parts of a NotesForm....

Can be annoying to have to updat all those actions...

Another gotcha is that Shared Actions although purporting to lessen maintenance also bring an aditional burden: by their nature the LotusScript inside Shared Actions cannot be compiled with full Option Declare type checking. So that is done later, in runtime. With all the problems that brings with it...
So now I only use Shared Actions for Simple Actions or Formula Language, and LotusScript is delegated to non-Shared Actions, usually containing only a call into a ScriptLibrary. Icode my agents the same way, so I never have to reschedule my Scheduled agents if there is a code upgrade (mostly). What helps there is the use of Option Private in a lib to force you to surface the interface by using the Public keyword where appropiate.  That way you minimize method and object signature changes.  These signature changes are what necessitate resaves of objects dependant on ScriptLibraries. And I avoid the resaves if possible.
@Lars: your comment is valid, but what's the relevance in this question? Cross-posting??    ^_^
ok... I've added this under the counter = 0 statement;
totalcount = notesViewEntryCollection.Count
I believe I realized that I cannot print using UIDOC as I want to be in total view mode not current document mode so I changed the uidoc DIM and print to:
  Dim uiview As NotesUIView
  Set uiview = workspace.Currentview

Call uiview.print

I'm still getting variant does not contain an object
Er? Print is a command, not a method in this case.

Print 123

It prints one line to the status bar in a front-end activity (not in background agents).
Hi Sjef... I get what your saying.
So I shouldn't even need the uiview. in front of the print ?

The object variant message is coming from the Set uiview = workspace.Currentview

I'm thinking I had to be in view mode with the current view.
I also added Dim workspace As New NotesUIWorkspace because the Workspace variant wasn't being set.
still getting the error now on this statement: totalcount = notesViewEntryCollection.Count
and I do not have the notesViewEntryCollection. prefix defined in a DIM statement.  How should this be defined ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note that using this property can be costly in terms of time. If you have other means of arriving at the total, these can be better performing.
lol... your right Sjef.... I couldn't remember the syntax.
Thank You !!

damn I'm rusty at this stuff.  Now I get a type mismatch back on the print statement.

      Call uiview.Print ("Processed " + CStr( counter ) + " of " + CStr( totalCount ) + " documents.")
      
Working it !!
Get rid of that uiview !!
oh yea... my bad.  I removed the Call and the uiview. the script is working and in debugger I see the print output.  I do not see the display box showing me the progress though when I run the agent from the view.... maybe I need more douments in the view to see it.  Testing continues..
You won't see a progress dialog box this way, ever. The Print text is displayed at the bottom of the Notes client, in the status bar, where you also see "You have new mail".
Also, if you lose the + and substitute &, you can get rid of the Cstr too..
Thank You all for your feedback.  Very much appreciated.  It's great having support like you available.<br />Thanks Again !!<br />Paul