• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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.

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
sjmmajor
Asked:
sjmmajor
  • 4
  • 3
  • 2
  • +1
2 Solutions
 
p_parthaCommented:
am not sure what u are trying to convey , but to get the second document, probably u can do this:

set doc = view.getfirstdocument
set secondoc = VIEW.GETnextdocument(doc)


partha
0
 
RanjeetRainCommented:
Ok here :)


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
 
RanjeetRainCommented:
I wanna add something:


If it is fixed that there would always be only 3 documents (or only 2 always, or only 4 always), i guess you can use a view rather.

Say, you store the data in docs based on form MyForm. Have a field called seq_no in the form. Now create 2/3/4 documents as per your need. Be sure to assign sequence numbers as per your priority. Now create a view. Lets say you name it MyView. Now code your agent in this way.



Dim session As New NotesSession
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set collection = db.GetView("MyView")

For i = 1 To collection.Count
  if i = GetShiftNo() then
     ' Perform operation
  End IF
  Set doc = collection.GetNthDocument( i )
Next



GetShiftNo is a sepearet function that allows you to identify which shift the agent is runing on. Probably you can use the Now() LS function to determine the shift.
0
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.

 
RanjeetRainCommented:
You may ofcourse use the GetFirstDocument and GetNextDocument methods, if you are more comforatble with that. My code just does that in a more programmatic way. Feel free to ask if you have a query.
0
 
RanjeetRainCommented:
I left some error in my code up there. Here is the correct version:



Dim session As New NotesSession
Dim db As NotesDatabase
Dim vw as NotesView
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set vw = db.GetView("MyView")
Set collection = vw.GetAllDocuments()

For i = 1 To collection.Count
 if i = GetShiftNo() then
    ' Perform operation
 End IF
 Set doc = collection.GetNthDocument( i )
Next
0
 
madheeswarCommented:
in Formulas use:

@subset(@DbColumn("":"";"";"yourVIEWname";column numberORfieldname);2)

use 2 for second document or 3 for 3rd document.
if u want last 2 and 3, then use -2 and -3 respectively.

U can use above code in Lotus Script also using Evaluate function.

-Thanks
0
 
sjmmajorAuthor Commented:
Just got back to this today.  Thanks for all the info.  Would I hard code the seq_no?  I want there to always be 3 documents which I have already created in the view.  I have a field called shift that I have 1,2, or 3 in.  GetShiftNo comes from where?  Here is a copy of the agent I was using.  How would your script fit into that?  

Sub Initialize
      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\xxxxxr\xxxx\xxxxxx1STnotes.xls")
      doc.Form = "1st Shift Production Report"
      doc.Subjectproductions = "xx"
      doc.productionrpt = "xxxxxx 1st Shift"
      doc.shift = "1"
      doc.createddate = notesdate.LocalTime
      doc.createdtime = notestime.LocalTime
      Call doc.Save( True, True )
      
End Sub

I have set up 3 agents.  1 for 1st, 1 for 2nd shift and 1 for 3rd shift.  I would like 1st to select 1st, 2nd to select the second document and 3rd to select the third one and replace the "body" with the appropriate attachment.

0
 
madheeswarCommented:
the below script will update the same info for all the documents in that view.
If u want to upload 3 separate attachments to every document, then use an array.
like:
dim arr(2) as string
arr(0)="pathforattach1"
arr(1)=
arr(2)=
instead of the below line,
 Set object = rtitem.EmbedObject _
     ( 1454 , "", "\\xxxx\xxxxxr\xxxx\xxxxxx1STnotes.xls")
use:
 Set object = rtitem.EmbedObject _
     ( 1454 , "", arr(k))
before loop keep k=0
and in the loop keep k=K+1


Sub Initialize
     Dim session As New NotesSession
     Dim db As NotesDatabase
dim view as notesview
     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 view=db.getview("yourViewName")
set doc=view.getfirstdocument
while not doc is nothing

Set rtitem = New NotesRichTextItem( doc, "Body" )
     Set doc.ProcessDate= notesdate
     Set object = rtitem.EmbedObject _
     ( 1454 , "", "\\xxxx\xxxxxr\xxxx\xxxxxx1STnotes.xls")
    ' doc.Form = "1st Shift Production Report"
     doc.Subjectproductions = "xx"
     doc.productionrpt = "xxxxxx 1st Shift"
     doc.shift = "1"
     doc.createddate = notesdate.LocalTime
     doc.createdtime = notestime.LocalTime
     Call doc.Save( True, True )
set doc=view.getnextdocument(doc)
wend
     'Set doc = New NotesDocument( db )
     
     
End Sub
0
 
sjmmajorAuthor Commented:
This is doing it at one time?  The file I am attaching is only updated on the shift so I don't want to change that document until their shift and then it would retain the last one.  So there would actually be 3 in the view at all times.
0
 
sjmmajorAuthor Commented:
I ended up using a view for each shift but I will keep all for future reference.  I am still using an agent which all your code really helped me see and understand the agents and script more.  Thanks so much for your time and effort.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now