[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

When I am running the below script it tells me that I can only run it from the view. I need to run it on a schedule.

What am I doing wrong?  Also can it replace the doument in the view instead of creating a new one each time?

Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim doc As NotesDocument
      Dim rtitem As NotesRichTextItem
      Dim object As NotesEmbeddedObject
      Dim notestime As New notesdatetime("")
      Dim notesdate As New notesdatetime("")
      notesdate.LocalTime = Date
      notestime.LocalTime = Time
      Set db = session.CurrentDatabase
      Set doc = New NotesDocument( db )
      Set rtitem = New NotesRichTextItem( doc, "Body" )
      Set doc.ProcessDate= notesdate
      Set object = rtitem.EmbedObject _
      ( 1454 , "", "\\xxxx\xxxx\xxxxxx\xxxx.xls")
      doc.Form = "xxxx"
      doc.Subjectproductions = "xx"
      doc.productionrpt = "xxxxxx"
      doc.createddate = notesdate.LocalTime
      doc.createdtime = notestime.LocalTime
      Call doc.Save( True, True )

End sub

Thank
0
sjmmajor
Asked:
sjmmajor
2 Solutions
 
HemanthaKumarCommented:
You have set the agent to run on selected docs.. change it to schedule more than once a day or daily

~Hemanth
0
 
qwaleteeCommented:
Hi sjmmajor,

The default way agents are create is to "run: Manuall from actions menu" and to "act on: selected documents."  That's not what you want to do.  You want it to "run: on schedule."  The schedule can be monthly, weekly, daily (once per day), or more than once per day (every five minutes, ten minutes, hour, four hours, 7 hours and 15 minutes, etc.).  That's the amount of time Domino will wait BETWEEN each run (from the end of one run to the start of the next).

You shoudl also set it to "act on: all documentsin database."  I know you really are not acting on all the database's documents -- your agent ignores the list of documents that Notes presents.  I only tell you to set this because it makes the agent manager more efficient.

-----

As to replacing the existing doc instead of creating a new one, here's how you do it.  Replace the following line:

     Set doc = New NotesDocument( db )

With:

     CONST viewName = "********** put the name of your view here -- preferably, this shoudl be a view that users do NOT see, so that if they ask for changes to a visible view, it does not affect your agent."
     Dim view as notesView
     Set view = db.getView(viewName)
     Set doc = view.getFIrstDocument
     If doc is Nothing then
         Set doc = New NotesDocument( db )
     Else
        doc.removeItem("Body") 'so the "Set rtItem = New NotesRichTextItem" does not fail; the other fields will be ok whether new doc/old doc, because, e.g., doc.Form = "..." creates OR replaces a value
     End If



Cheers!
0
 
sjmmajorAuthor Commented:
qwaletee - the change to the agent for replacing worked well.  GREAT!!  

I changed the agent to schedule and on all documents and right now I have it schedule to run every 10 mins but it isn't running.  I have other scheduled agents that do run and I looked at them but can't see any differences.  

Any other ideas??

0
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.

 
sjmmajorAuthor Commented:
I had to change the restrictions to allow restricted operations for the agent to run on schedule.  So the schedule part is completed and I thank all.  I will split points.

I can open another question if you would like but you know when you use view.getfirstdocument?  Can I select second document or 3rd document?  As I am thinking about it, I am going to be running this for 3 shifts and want to maintain 3 documents.

0
 
RanjeetRainCommented:
It would be fair to open a new question for this. I am posting it here just because you haven't posted the new one yet ;-)


Shcedule agents - Shcedule agents do not run on a view. Any attempt to do a getfirstdocument would be fruitless untill you have a view handle. THe method to loop thru the set of the documents eligible for run is to use the UnprocessedDocuments proeprty of the NotesDatabase class. This property returns you a NotesDocumentCollection object. See designer help to learn more on how to use this property.


From the designer help.

Read-only. The documents in a database that the current agent or view action considers to be "unprocessed." The type of agent determines which documents are considered unprocessed.

Example code:

Sub Click(Source As Button)
  Dim session As New NotesSession
  Dim db As NotesDatabase
  Dim collection As NotesDocumentCollection
  Dim doc As NotesDocument
  Set db = session.CurrentDatabase
  Set collection = db.UnprocessedDocuments
  For i = 1 To collection.Count
    Set doc = collection.GetNthDocument( i )
    Set item = doc.GetFirstItem( "Approver" )
    If item.Contains( session.UserName ) Then
      doc.Approved = "Yes"
      Call doc.Save( False, True )
    End If
  Next
End Sub
0
 
sjmmajorAuthor Commented:
I have just posted the question.  Can you put your entry there or is there something I can do?
0
 
sjmmajorAuthor Commented:
Thanks to all!!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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