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

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

Creating a document through a scheduled agent that will get field values based off of another document

I have created database in Lotus Notes.  The purpose of this database is to track scheduled ITV events.  The simple side of the database is merely filling out a form with the pertinent information for the event.  Fields in the event form are "EventTime", "EventLocation", "EventTech", "EvenEquip" and so forth.  There are also several hidden fields within the form to compute values and such as well as send notifications to people when the are created, re-scheduled, or Canceled.

The part that I am having difficulty with is the following.  I have created another form to be filled out and used in order to "automatically" create REGULAR, REPEATING events that occur, once a week, the 2nd Tuesday of the month and so on.  I believe I have all of the coding that I need to have in this form in order to calculate it correctly.  However, I can't seem to figure out HOW TO HAVE AN AGENT THAT WILL DO THE FOLLOWING:

At scheduled times, this agent will search the DB for all forms of name "Repeat1".  The agent will then use that form to create a new form of name "ITV1".  The field values of the "Repeat1" document will be used in the "ITV1" document that it creates.  All scheduled ITV events use the form name "ITV1".

I am fairly proficient with Formula language.  However, rather lacking with LotusScript experience.  As such, the entire DB is done with Formula as of now.

Please let me know at your earliest convenience if you have a solution or a suggestion to this problem.

TIA,
--patrick
0
phertel2
Asked:
phertel2
  • 2
1 Solution
 
HemanthaKumarCommented:
Write agent which is scheduled per your requirement.. Click on Add Search Button and select the field and value (Repeat1)

In the program pane, Select LS

this will be your code..

Dim s as New NotesSession
dim db as Notesdatabase
dim doc as NotesDocument, ndoc as NotesDocument
Dim col as NotesDocumentCollection

set db = s.CurrentDatabase
set col = db.UnprocessedDocuments
set doc = col.GetFirstDocument
while not doc is nothing
' set ndoc = doc.CopyToDatabase(db) ' This copies all the field values and then you can remove fields needed. or
set ndoc = db.CreateDocument
' Set field values here... this is ideal if you are interested only in few fields to be copied from original
doc.Save false, false
set doc = col.GetNextDocument(doc)
wend

~Hemanth
0
 
qwaleteeCommented:
WHatis ITV?  Interactive television?

You might want to consider just using the standard resource reservations and mail templates for this.  Al pre-built, allows you to manage equipment and location for the "meeting," and repeats are a built-in feature.
0
 
qwaleteeCommented:
Using formula alone, you could also get this job done.  Create an agent as if all you are doing is modifying a Repeat1 form to BECOME an ITV1 form (as if you are transofmring the document, getting rid of Repeat1 and tunring that very document in ITV1).

Then, change the agent option from "modify documents" to "create new documents"
0
 
phertel2Author Commented:
My appologies for the lag of time here...

I finally got the code to work with the following:

-->

Dim db As Notesdatabase
Dim doc As NotesDocument, ndoc As NotesDocument
Dim col As NotesDocumentCollection
Dim item As NotesItem, list1 As NotesItem


Sub Initialize
      Dim s As New NotesSession      
      
      Dim dateTime As New NotesDateTime( "" )
      Dim dateTimeSun As New NotesDateTime( "" )
      Dim dateTimeMon As New NotesDateTime( "" )
      Dim dateTimeTue As New NotesDateTime( "" )
      Dim dateTimeWed As New NotesDateTime( "" )
      Dim dateTimeThur As New NotesDateTime( "" )
      Dim dateTimeFri As New NotesDateTime( "" )
      Dim dateTimeSat As New NotesDateTime( "" )
      
      Call dateTime.SetNow
      Call dateTimeSun.SetNow
      Call dateTimeMon.SetNow
      Call dateTimeTue.SetNow
      Call dateTimeWed.SetNow
      Call dateTimeThur.SetNow
      Call dateTimeFri.SetNow
      Call dateTimeSat.SetNow
      
      Set db = s.CurrentDatabase
      Set col = db.UnprocessedDocuments
      Set doc = col.GetFirstDocument
      Set list1 = doc.GetFirstItem("RptDay1")
      
      DateRef = Now
      If Weekday(DateRef) = 1 Then
            Call dateTimeSun.AdjustDay(0)
            Call dateTimeMon.AdjustDay(1)
            Call dateTimeTue.AdjustDay(2)
            Call dateTimeWed.AdjustDay(3)
            Call dateTimeThur.AdjustDay(4)
            Call dateTimeFri.AdjustDay(5)
            Call dateTimeSat.AdjustDay(6)
      Elseif Weekday(DateRef) = 2 Then
            Call dateTimeSun.AdjustDay(-1)
            Call dateTimeMon.AdjustDay(0)
            Call dateTimeTue.AdjustDay(1)
            Call dateTimeWed.AdjustDay(2)
            Call dateTimeThur.AdjustDay(3)
            Call dateTimeFri.AdjustDay(4)
            Call dateTimeSat.AdjustDay(5)
      Elseif Weekday(DateRef) = 3 Then
            Call dateTimeSun.AdjustDay(-2)
            Call dateTimeMon.AdjustDay(-1)
            Call dateTimeTue.AdjustDay(0)
            Call dateTimeWed.AdjustDay(1)
            Call dateTimeThur.AdjustDay(2)
            Call dateTimeFri.AdjustDay(3)
            Call dateTimeSat.AdjustDay(4)
      Elseif Weekday(DateRef) = 4 Then
            Call dateTimeSun.AdjustDay(-3)
            Call dateTimeMon.AdjustDay(-2)
            Call dateTimeTue.AdjustDay(-1)
            Call dateTimeWed.AdjustDay(0)
            Call dateTimeThur.AdjustDay(1)
            Call dateTimeFri.AdjustDay(2)
            Call dateTimeSat.AdjustDay(3)
      Elseif Weekday(DateRef) = 5 Then
            Call dateTimeSun.AdjustDay(-4)
            Call dateTimeMon.AdjustDay(-3)
            Call dateTimeTue.AdjustDay(-2)
            Call dateTimeWed.AdjustDay(-1)
            Call dateTimeThur.AdjustDay(0)
            Call dateTimeFri.AdjustDay(1)
            Call dateTimeSat.AdjustDay(2)
      Elseif Weekday(DateRef) = 6 Then
            Call dateTimeSun.AdjustDay(-5)
            Call dateTimeMon.AdjustDay(-4)
            Call dateTimeTue.AdjustDay(-3)
            Call dateTimeWed.AdjustDay(-2)
            Call dateTimeThur.AdjustDay(-1)
            Call dateTimeFri.AdjustDay(0)
            Call dateTimeSat.AdjustDay(1)
      Else
            Call dateTimeSun.AdjustDay(-6)
            Call dateTimeMon.AdjustDay(-5)
            Call dateTimeTue.AdjustDay(-4)
            Call dateTimeWed.AdjustDay(-3)
            Call dateTimeThur.AdjustDay(-2)
            Call dateTimeFri.AdjustDay(-1)
            Call dateTimeSat.AdjustDay(0)
      End If
      
      While Not doc Is Nothing
            If list1.Contains( "Monday" ) Then
                  Set ndoc = db.CreateDocument
                  Set item = doc.GetFirstItem("RptEventType")
                  Call item.CopyItemToDocument(ndoc, "EventType")
                  Set item = doc.GetFirstItem("RptEventName")
                  Call item.CopyItemToDocument(ndoc, "EventName")
                  Set item = doc.GetFirstItem("RptEventContact1")
                  Call item.CopyItemToDocument(ndoc, "EventContact1")
                  Set item = doc.GetFirstItem("RptEventContactPhone1")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone1")
                  Set item = doc.GetFirstItem("RptEventContact2")
                  Call item.CopyItemToDocument(ndoc, "EventContact2")
                  Set item = doc.GetFirstItem("RptEventContactPhone2")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone2")
                  Set item = doc.GetFirstItem("RptEventStartTime")
                  Call item.CopyItemToDocument(ndoc, "EventStartTime")
                  Set item = doc.GetFirstItem("RptEventEndTime")
                  Call item.CopyItemToDocument(ndoc, "EventEndTime")
                  Set item = doc.GetFirstItem("RptEventLocation")
                  Call item.CopyItemToDocument(ndoc, "EventLocation")
                  Set item = doc.GetFirstItem("RptEventTech1")
                  Call item.CopyItemToDocument(ndoc, "EventTech1")
                  Set item = doc.GetFirstItem("RptEventEquip1")
                  Call item.CopyItemToDocument(ndoc, "EventEquip1")
                  Set item = doc.GetFirstItem("RptNetworkConn")
                  Call item.CopyItemToDocument(ndoc, "NetworkConn")
                  Set item = doc.GetFirstItem("RptWebEx1")
                  Call item.CopyItemToDocument(ndoc, "WebEx1")
                  Set item = doc.GetFirstItem("RptVTELNumber")
                  Call item.CopyItemToDocument(ndoc, "VTELNumber")
                  Set item = doc.GetFirstItem("RptComment1")
                  Call item.CopyItemToDocument(ndoc, "Comment1")
                  Call ndoc.replaceItemValue("OracleCheck1", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck2", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck3", "Yes")
                  Call ndoc.replaceItemValue("EventDateStart", dateTimeMon)
                  ndoc.Save True, False
            End If
            
            If list1.Contains( "Tuesday" ) Then
                  Set ndoc = db.CreateDocument
                  Set item = doc.GetFirstItem("RptEventType")
                  Call item.CopyItemToDocument(ndoc, "EventType")
                  Set item = doc.GetFirstItem("RptEventName")
                  Call item.CopyItemToDocument(ndoc, "EventName")
                  Set item = doc.GetFirstItem("RptEventContact1")
                  Call item.CopyItemToDocument(ndoc, "EventContact1")
                  Set item = doc.GetFirstItem("RptEventContactPhone1")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone1")
                  Set item = doc.GetFirstItem("RptEventContact2")
                  Call item.CopyItemToDocument(ndoc, "EventContact2")
                  Set item = doc.GetFirstItem("RptEventContactPhone2")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone2")
                  Set item = doc.GetFirstItem("RptEventStartTime")
                  Call item.CopyItemToDocument(ndoc, "EventStartTime")
                  Set item = doc.GetFirstItem("RptEventEndTime")
                  Call item.CopyItemToDocument(ndoc, "EventEndTime")
                  Set item = doc.GetFirstItem("RptEventLocation")
                  Call item.CopyItemToDocument(ndoc, "EventLocation")
                  Set item = doc.GetFirstItem("RptEventTech1")
                  Call item.CopyItemToDocument(ndoc, "EventTech1")
                  Set item = doc.GetFirstItem("RptEventEquip1")
                  Call item.CopyItemToDocument(ndoc, "EventEquip1")
                  Set item = doc.GetFirstItem("RptNetworkConn")
                  Call item.CopyItemToDocument(ndoc, "NetworkConn")
                  Set item = doc.GetFirstItem("RptWebEx1")
                  Call item.CopyItemToDocument(ndoc, "WebEx1")
                  Set item = doc.GetFirstItem("RptVTELNumber")
                  Call item.CopyItemToDocument(ndoc, "VTELNumber")
                  Set item = doc.GetFirstItem("RptComment1")
                  Call item.CopyItemToDocument(ndoc, "Comment1")
                  Call ndoc.replaceItemValue("OracleCheck1", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck2", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck3", "Yes")
                  Call ndoc.replaceItemValue("EventDateStart", dateTimeTue)
                  ndoc.Save True, False
            End If
            
            If list1.Contains( "Wednesday" ) Then
                  Set ndoc = db.CreateDocument
                  Set item = doc.GetFirstItem("RptEventType")
                  Call item.CopyItemToDocument(ndoc, "EventType")
                  Set item = doc.GetFirstItem("RptEventName")
                  Call item.CopyItemToDocument(ndoc, "EventName")
                  Set item = doc.GetFirstItem("RptEventContact1")
                  Call item.CopyItemToDocument(ndoc, "EventContact1")
                  Set item = doc.GetFirstItem("RptEventContactPhone1")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone1")
                  Set item = doc.GetFirstItem("RptEventContact2")
                  Call item.CopyItemToDocument(ndoc, "EventContact2")
                  Set item = doc.GetFirstItem("RptEventContactPhone2")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone2")
                  Set item = doc.GetFirstItem("RptEventStartTime")
                  Call item.CopyItemToDocument(ndoc, "EventStartTime")
                  Set item = doc.GetFirstItem("RptEventEndTime")
                  Call item.CopyItemToDocument(ndoc, "EventEndTime")
                  Set item = doc.GetFirstItem("RptEventLocation")
                  Call item.CopyItemToDocument(ndoc, "EventLocation")
                  Set item = doc.GetFirstItem("RptEventTech1")
                  Call item.CopyItemToDocument(ndoc, "EventTech1")
                  Set item = doc.GetFirstItem("RptEventEquip1")
                  Call item.CopyItemToDocument(ndoc, "EventEquip1")
                  Set item = doc.GetFirstItem("RptNetworkConn")
                  Call item.CopyItemToDocument(ndoc, "NetworkConn")
                  Set item = doc.GetFirstItem("RptWebEx1")
                  Call item.CopyItemToDocument(ndoc, "WebEx1")
                  Set item = doc.GetFirstItem("RptVTELNumber")
                  Call item.CopyItemToDocument(ndoc, "VTELNumber")
                  Set item = doc.GetFirstItem("RptComment1")
                  Call item.CopyItemToDocument(ndoc, "Comment1")
                  Call ndoc.replaceItemValue("OracleCheck1", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck2", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck3", "Yes")
                  Call ndoc.replaceItemValue("EventDateStart", dateTimeWed)
                  ndoc.Save True, False
            End If
            
            If list1.Contains( "Thursday" ) Then
                  Set ndoc = db.CreateDocument
                  Set item = doc.GetFirstItem("RptEventType")
                  Call item.CopyItemToDocument(ndoc, "EventType")
                  Set item = doc.GetFirstItem("RptEventName")
                  Call item.CopyItemToDocument(ndoc, "EventName")
                  Set item = doc.GetFirstItem("RptEventContact1")
                  Call item.CopyItemToDocument(ndoc, "EventContact1")
                  Set item = doc.GetFirstItem("RptEventContactPhone1")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone1")
                  Set item = doc.GetFirstItem("RptEventContact2")
                  Call item.CopyItemToDocument(ndoc, "EventContact2")
                  Set item = doc.GetFirstItem("RptEventContactPhone2")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone2")
                  Set item = doc.GetFirstItem("RptEventStartTime")
                  Call item.CopyItemToDocument(ndoc, "EventStartTime")
                  Set item = doc.GetFirstItem("RptEventEndTime")
                  Call item.CopyItemToDocument(ndoc, "EventEndTime")
                  Set item = doc.GetFirstItem("RptEventLocation")
                  Call item.CopyItemToDocument(ndoc, "EventLocation")
                  Set item = doc.GetFirstItem("RptEventTech1")
                  Call item.CopyItemToDocument(ndoc, "EventTech1")
                  Set item = doc.GetFirstItem("RptEventEquip1")
                  Call item.CopyItemToDocument(ndoc, "EventEquip1")
                  Set item = doc.GetFirstItem("RptNetworkConn")
                  Call item.CopyItemToDocument(ndoc, "NetworkConn")
                  Set item = doc.GetFirstItem("RptWebEx1")
                  Call item.CopyItemToDocument(ndoc, "WebEx1")
                  Set item = doc.GetFirstItem("RptVTELNumber")
                  Call item.CopyItemToDocument(ndoc, "VTELNumber")
                  Set item = doc.GetFirstItem("RptComment1")
                  Call item.CopyItemToDocument(ndoc, "Comment1")
                  Call ndoc.replaceItemValue("OracleCheck1", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck2", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck3", "Yes")
                  Call ndoc.replaceItemValue("EventDateStart", dateTimeThur)
                  ndoc.Save True, False
            End If
            
            If list1.Contains( "Friday" ) Then
                  Set ndoc = db.CreateDocument
                  Set item = doc.GetFirstItem("RptEventType")
                  Call item.CopyItemToDocument(ndoc, "EventType")
                  Set item = doc.GetFirstItem("RptEventName")
                  Call item.CopyItemToDocument(ndoc, "EventName")
                  Set item = doc.GetFirstItem("RptEventContact1")
                  Call item.CopyItemToDocument(ndoc, "EventContact1")
                  Set item = doc.GetFirstItem("RptEventContactPhone1")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone1")
                  Set item = doc.GetFirstItem("RptEventContact2")
                  Call item.CopyItemToDocument(ndoc, "EventContact2")
                  Set item = doc.GetFirstItem("RptEventContactPhone2")
                  Call item.CopyItemToDocument(ndoc, "EventContactPhone2")
                  Set item = doc.GetFirstItem("RptEventStartTime")
                  Call item.CopyItemToDocument(ndoc, "EventStartTime")
                  Set item = doc.GetFirstItem("RptEventEndTime")
                  Call item.CopyItemToDocument(ndoc, "EventEndTime")
                  Set item = doc.GetFirstItem("RptEventLocation")
                  Call item.CopyItemToDocument(ndoc, "EventLocation")
                  Set item = doc.GetFirstItem("RptEventTech1")
                  Call item.CopyItemToDocument(ndoc, "EventTech1")
                  Set item = doc.GetFirstItem("RptEventEquip1")
                  Call item.CopyItemToDocument(ndoc, "EventEquip1")
                  Set item = doc.GetFirstItem("RptNetworkConn")
                  Call item.CopyItemToDocument(ndoc, "NetworkConn")
                  Set item = doc.GetFirstItem("RptWebEx1")
                  Call item.CopyItemToDocument(ndoc, "WebEx1")
                  Set item = doc.GetFirstItem("RptVTELNumber")
                  Call item.CopyItemToDocument(ndoc, "VTELNumber")
                  Set item = doc.GetFirstItem("RptComment1")
                  Call item.CopyItemToDocument(ndoc, "Comment1")
                  Call ndoc.replaceItemValue("OracleCheck1", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck2", "Yes")
                  Call ndoc.replaceItemValue("OracleCheck3", "Yes")
                  Call ndoc.replaceItemValue("EventDateStart", dateTimeFri)
                  ndoc.Save True, False
            End If
            
            Call doc.replaceItemValue("TmpSave1", "1")
            doc.Save True, False
            Set doc = col.GetNextDocument(doc)
      Wend
      
End Sub

-->

Probably too much and over complicated, but it works.  That solves the WEEKLY agent.  Now my problem is getting a monthly scheduled event to work right.  (1st Monday; 3rd Wednesday; etc).  I can't seem to figure out the correct trigger action for it and so on so that it will always keep it scheduled for the next two months.

Thanks to both of you for your help.  Yes, ITV does stand for Interactive TeleVision.

I will be accepting Hemanth's answer as it was first and I did end up going with LotusScript.  I couldn't quite see how formula could pull off entirely what I needed -->  (I am decent with Formula, just not as expierenced as I need to be!)

Thanks!
--patrick
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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