?
Solved

Script Mod

Posted on 2004-09-02
13
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11966882
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
ID: 11967731
I will try next week and update you. Thanks alot.
0
 

Author Comment

by:schmad01
ID: 11997523
Tried it, but filleddate1 field is still blank.  It is a time-date field set as computed when composed.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 46

Expert Comment

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

Author Comment

by:schmad01
ID: 11997988
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
ID: 11998088
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
 

Author Comment

by:schmad01
ID: 11998305
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
ID: 11998415
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
ID: 11999801
I tried it in different earlier positions. Still nothing.  Strange.
0
 

Author Comment

by:schmad01
ID: 11999856
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 1000 total points
ID: 12004119
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
ID: 12017889
You got it. Thanks, Sjef.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12018579
:)
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

777 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