Solved

Batch updating of Lotus Notes document

Posted on 2001-08-15
6
466 Views
Last Modified: 2013-12-18
Hi
  I got a problem here. I got a form with the following fields:
a) Date - datetime data type
b) dattype -  radio button. Choices are "work-day", "Saturday", "Sunday", "Holiday"
c) Startwork - datetime datatype
d) endwork - datetime datatype
e) OT_claimable - Radio button. Choices are "Yes" or No""
f) Timespent - number
g) Overtime - number

I need to recalculate the "Timespent" & "Overtime" for all documents.There were some bugs before hands.
I have the script below which does all the calculation.
Please advise who how can I recalculate all the documents using the correct formula. I have a view which display all the fields (a) - (g). The view name is "Timesheetentryview".

Sub Click(Source As Button)
     Dim x As New Notesuiworkspace
     Dim u As notesuidocument
     Set u = x.currentdocument
     Dim timetaken As  Double
     Dim Roundedtime As Double
     Dim texttime As String
     Dim dummey As Double
     Dim Starttime  As NotesDatetime
     Dim EndTime As NotesDatetime
     Dim OTStartTime As NotesDateTime
     Dim mOvertime As  String
     Dim OTYesNo As String
     Dim mDaytype As String
     Dim      mweekday As String
     OTYesNo = u.FieldGetText ("OT_claimable")
     mDaytype = u.FieldGetText("daytype")
     Set StartTime = New NotesDatetime(u.fieldgetText("StartWork"))
     Set EndTime = New NotesDatetime (u.fieldgetText("EndWork"))
     Set OTStartTime = New NotesDateTime( u.FieldGetText("OTstarttimefield"))
     dummey = (EndTime.TimeDifference(OTStartTime))
     
     timetaken =  ( endTime.TimeDifference (Starttime))  / 3600  
     texttime =  timetaken
     
     If OTYesNo ="Yes"   And  mdaytype ="Work-Day"  Then
          If  (endtime.TimeDifference(OTStartTime)) / 3600   <  0  Then              
               Messagebox "Time end is before 17:30 and Claimable flag was set to Yes. Claimable flag has been set to No for you" , , "OverTime Flag"
'          Messagebox  OTYesNo  , , "OTyesno"
               OTYesNo ="No"
               mOvertime =  0          
               Call u.fieldsettext("OT_claimable","No" )
          End If 'end if for end time before 5.30pm
'          End If  'end if for dattype ='work-day'
     End If ' end if for OTYESNO = 'yes'
     
     Select Case mdaytype
     Case "Work-Day":
          If OTYesNo ="Yes" Then
               
               
               If  (endtime.TimeDifference(OTStartTime)) / 3600 < 0 Then  'Use Time difference to determine when the over-time start at 17:30 or before 17:30.
                    mOvertime =  0
               End If
               If  (endtime.TimeDifference(OTStartTime)) / 3600 > 0 Then  'Use Time difference to determine when the over-time start at 17:30 or before 17:30.
                    mOvertime =  ( endTime.TimeDifference (OTStartTime))  / 3600      
               End If
               
               
               
          Else
               mOvertime = 0
               
          End If
     Case "Saturday":
          mOvertime =  ( endTime.TimeDifference (StartTime))  / 3600      
     Case  "Sunday":
          mOvertime =  ( endTime.TimeDifference (StartTime))  / 3600      
     Case "Holiday":
          mOvertime =  ( endTime.TimeDifference (StartTime))  / 3600      
     End Select    
     
     
     Call u.fieldsettext("TimeSpent", texttime)
     Call u.fieldsettext("Overtime", mOverTime)
     
     u.save
     u.close
End Sub

0
Comment
Question by:CT2000
  • 3
  • 2
6 Comments
 

Expert Comment

by:CommView
ID: 6391704
Hi,

You can reuse your code, but you have to modify it lightly.
These are the steps you must take (have your Notes Designer help standby in case you want to know what you're doing).
1. Copy your code to the clipboard
2. Create a shared agent
3. Have the agent "Run from the Action menu"
4. Have the agent act on "Selected documents"
5. Select LotusScript in the "Run" listbox
6. Paste your code into the initialize section.
7a. Dim a NotesDocument (e.g. Dim doc as NotesDocument)
7b. Dim a NotesDocumentCollection (e.g. Dim dcSelected as
NotesDocumentCollection
7c. Dim a NotesSession (e.g. Dim session as New NotesSession)
7d. Dim a NotesDatabase (e.g. Dim db as NotesDatabase)
8. Rewrite your code so it uses the background document (doc) instead of the NotesUIDocument
9. remove all user input/output for you are going to run the code in "batch mode" and you probably don't want to be bothered with x-times the same question.

Now comes the hard part:
10. After the "Dim"-lines enter these lines of code:
   set db = session.CurrentDatabase
   set dcSelected = db.UnprocessedDocuments
   set doc = dcSelected.GetFirstDocument
   do while not (doc is Nothing)
11. After your line "u.save" (Which you will have to rewrite to "doc.save( true, true, true)", enter these lines:
   set doc = dcSelected.GetNextDocument( doc )
   loop

Now you can run the agent from the actions menu in any view. The agent will run on all selected documents in the view (that is: all documents that are ticked).

You know: backend classes in Notes are so much more fun than frontend classes!

Have fun and good luck. If you want more assistance, let me know through this forum.

Wiebe van Bruggen
0
 

Author Comment

by:CT2000
ID: 6392959
Hi,
  How can I get content of the document into my script? I have the view "Timesheetentryview". How can I update the info back?

  Please advise.
  Thanks in advance
  CT2000
0
 
LVL 18

Accepted Solution

by:
marilyng earned 50 total points
ID: 6401903
The back end protocols suggested by Wiebe will update the selected documents in a view.  If the view is set to "update automatically" or show the "refresher" arrow, as soon as you run and complete the agent, the view will refresh.

However, you could instantiate the view in your code:

Dim view as NotesView
Set view = db.getview("Timesheetentryview")
view.refresh

and insert this after all the loops have concluded. If the view is set to refresh automatically, then the results should be visible, otherwise you would see the "refresher" arrow at the top of the view.

To see the results in the document, you would simple click on the document and open it.

Hope this helps.

Marilyn
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:CT2000
ID: 6402742
Hi,
  I still stuck in how to get the info from the document which appear in the view to be in my script. Will the syntax be the same as that for the NotesDocument?

  Please advise?
  Thanks in advance.
  CT2000
0
 
LVL 18

Expert Comment

by:marilyng
ID: 6402863
Ct2000,

No the syntax for the backend is different, especially if you're using the collection to process selected documents from a view.  IT would look something like this:

----------------------------
        Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim Collection As NotesDocumentCollection
     Dim view As NotesView
     Dim doc As NotesDocument
     
     Dim timetaken As  Double
     Dim Roundedtime As Double
     Dim texttime As String
     Dim dummey As Double
     Dim Starttime  As New NotesDatetime("")
     Dim EndTime As New NotesDatetime("")
     Dim OTStartTime As New NotesDateTime("")
     Dim mOvertime As  String
     Dim OTYesNo As String
     Dim mDaytype As String
     Dim  mweekday As String
     
     Dim timeItem As NotesItem
     
     Set db = session.currentdatabase
     Set view = db.getview("nameofyourview")    
     Set collection = db.unprocesseddocuments
     
     If collection.count >0 Then
     
     Set doc = collection.getfirstdocument
     Do While Not doc Is Nothing
          With doc
               OTYesNo =.OT_claimable
               mDayType = .daytype
               Set timeItem = .GetFirstItem( "StartWork" )
               Set StartTime = timeItem.DateTimeValue
               Set timeItem = .GetFirstItem("EndWork")
               Set EndTime = timeItem.DateTimeValue
               ' and so on... to collect the values
               ' then create a branch sub here to save the new values to the document
               ' for instance
               
               If OTYesNo ="Yes"   And  mdaytype ="Work-Day"  Then
                    If  (endtime.TimeDifference(OTStartTime)) / 3600   <  0  Then            
                         
                         OTYesNo ="No"
                         mOvertime =  0          
                         .OT_claimable="No"
                    End If 'end if for end time before 5.30pm'
               End If ' end if for OTYESNO = 'yes'
               .save True, True              
          End With
         
          Set doc = collection.getnextdocument(doc)
         
     Loop
End If         'collection is nothing
     Goto ExitHere
     
Errorhandler:
     'error handling code here
     Goto Exithere
     
ExitHere:
     Set collection = Nothing
-----------------------------------------------    

I think you'll have to copy and paste this into a notepad to see it, but you get the idea.  You don't really need the messagebox messages because the document isn't really open on the front end and as I understand it, you want to process a lot of documents without really opening them. Your script doesn't seem to need user input.  All you need to do is construct a view, and then use your code in an agent and call the agent from a view button.

The user selects the documents that need processing and mashes the button, the agent steps through selected documents and updates them.  If you want, you can add a "processed" boolean field that your view can show as an icon (like a check) and tell you which documents were updated.

Does this answer your question?

Marilyn
0
 

Author Comment

by:CT2000
ID: 6408973
Hi,
  The script only manage to update one record and it exit.
I have change the
" Set doc = collection.getfirstdocument" to "Set doc = view.getfirstdocument"
   Somehow the script does not update the data into the view. I try doing some testing on the field update by writing the script as below.
                   
 If OTYesNo ="Yes" Then
    OTYesNo = "No"
 End If    
  What I have is the OT_claimable field will change to " "

  CT2000
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now