Solved

Script Mod

Posted on 2004-09-02
13
233 Views
Last Modified: 2013-12-18
Can someone update this code so that when the field b_status is entered or changed as "Filled"
it will update a timedate field on the form called filleddate1 with the current time.  and......

when the b_status_1 is entered or changed as "Filled" will update a timedate field on the form called filleddate2 with the current time.

Thanks.
Here is the code:

'Update_OOTS:

Sub Click(Source As Button)
      On Error Goto ErrROutine
      Dim session As New NotesSession
      Dim ws As New notesuiworkspace
      Dim uidoc As notesuidocument
      Set uidoc = ws.currentdocument
      Set doc = uidoc.document
      
      Dim fldArr(2), fldValArr(2)
      fldArr(0) = "stat_modby"
      fldValArr(0) = session.CommonUserName
      fldArr(1) = "stat_modtime"
      fldValArr(1) = Now()
      fldArr(2) = "b_status"
      fldValArr(2) = doc.b_action(0)
      
      ret = SetVal ( "Batch_Update_View", fldArr, fldValArr, doc.b_number(0) )
      If Not ret Then
            Msgbox "Updates to first view were not successful"
      Else
            fldArr(0) = "stat_modby_1"
            fldValArr(0) = session.CommonUserName
            fldArr(1) = "stat_modtime_1"
            fldValArr(1) = Now()
            fldArr(2) = "b_status_1"
            fldValArr(2) = doc.b_action(0)  ' This is the value set to b_status_1 field
            ret = SetVal ( "Batch_Update_View_2", fldArr, fldValArr, doc.b_number(0) )
            If Not ret Then
                  Msgbox "Updates to second view were not successful"
            Else
                  If Messagebox("Update Successful! Do you want to close this form ?",4 + 32 ,"Close Document ?") = 6 Then
                        uidoc.Close
                  End If
            End If
            
      End If
      Exit Sub
      
ErrRoutine:
      Messagebox "Error" & Str(Err) & ": " & Error$
      Exit Sub
      
      
      
End Sub
Function SetVal( ViewName As String, FieldName As Variant, FieldValue As Variant, KeyValue As String) As Variant
      SetVal = False
      Dim session As New notessession
      Dim db As notesdatabase
      Dim view As NotesView
      Set db = session.currentdatabase
      Set view = db.getview(ViewName)          ' Change the View Name
      If Not view Is Nothing Then
            Set doccoll = view.getalldocumentsbykey(KeyValue)     ' Change the Key Name
            Print doccoll.Count & " docs found "
            If doccoll.count > 0 Then
                  Forall f In FIeldName
                        Call doccoll.StampAll( f , FieldValue(Arraygetindex( FieldName, f )) )
                  End Forall
            End If
            SetVal = True
      Else
            Msgbox "View: " & ViewName & " Not Found !!"
      End If
      
End Function

0
Comment
Question by:schmad01
  • 7
  • 6
13 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
How 'bout

    If doc.b_status(0)="Filled" Then
        doc.filleddate1= Now
    End If
   
somewhere in your code? Yours to pick the place ;)

Just a warning: I'm afraid that the SetVal function is VERY inefficient if there are many documents in the collection and there are many fields to be set. The StampAll method will internally do an open, change and save of the documents, so each time you call StampAll, the document is opened, changed and saved again. I don't know where the break-even point is as compared to a standard loop with the standard GetNextDocument and Save calls.
0
 

Author Comment

by:schmad01
Comment Utility
I will try next week and update you. Thanks alot.
0
 

Author Comment

by:schmad01
Comment Utility
Tried it, but filleddate1 field is still blank.  It is a time-date field set as computed when composed.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
Why computed when composed? And did you save the document after modifying the field?
0
 

Author Comment

by:schmad01
Comment Utility
Tried changing the field to Editable to test it.  Still nothing.  Also note that this button script is on a form outside of the form that is actually being updated.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
Okay. Where in your code did you add the lines updating the filleddate1 field? Did you try to enable Debug-mode and walk through your code?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:schmad01
Comment Utility
I put it here:  

Else
            fldArr(0) = "stat_modby_1"
            fldValArr(0) = session.CommonUserName
            fldArr(1) = "stat_modtime_1"
            fldValArr(1) = Now()
            fldArr(2) = "b_status_1"
            fldValArr(2) = doc.b_action(0)  ' This is the value set to b_status_1 field
            ret = SetVal ( "Batch_Update_View_2", fldArr, fldValArr, doc.b_number(0) )
            If Not ret Then
                  Msgbox "Updates to second view were not successful"
            Else
                  If Messagebox("Update Successful! Do you want to close this form ?",4 + 32 ,"Close Document ?") = 6 Then
                        uidoc.Close
                  End If
            End If

           If doc.b_status(0)="Filled" Then
           doc.filleddate1= Now
          End If

            
      End If
      Exit Sub
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
You just picked the one place NOT to put the statements :) After uidoc.Close, there is no script anymore. It should therefore work if you say No to closing the document. Try that.

ANyway: place the lines somewhat earlier in your code.
0
 

Author Comment

by:schmad01
Comment Utility
I tried it in different earlier positions. Still nothing.  Strange.
0
 

Author Comment

by:schmad01
Comment Utility
Maybe I could create an agent to fill in the field. How could I call an agent from within the script if b_status = "Filled" ?
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 250 total points
Comment Utility
schmad01,

> Else
>           fldArr(0) = "stat_modby_1"
>           fldValArr(0) = session.CommonUserName
>           fldArr(1) = "stat_modtime_1"
>           fldValArr(1) = Now()
>           fldArr(2) = "b_status_1"
>           fldValArr(2) = doc.b_action(0)  ' This is the value set to b_status_1 field
>           ret = SetVal ( "Batch_Update_View_2", fldArr, fldValArr, doc.b_number(0) )
>           If Not ret Then
>                Msgbox "Updates to second view were not successful"
>           Else
                 If doc.b_status(0)="Filled" Then
                     doc.filleddate1= Now
--->                 Call doc.Save(True,False,True)
                 End If
>                If Messagebox("Update Successful! Do you want to close this form ?",4 + 32 ,"Close Document ?") = 6 Then
>                     uidoc.Close
>                End If
>           End If
>

You always have to save the document afterwards, but only if the document on screen is not in edit-mode.

Sjef
0
 

Author Comment

by:schmad01
Comment Utility
You got it. Thanks, Sjef.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
:)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

7 Experts available now in Live!

Get 1:1 Help Now