Solved

Script Mod

Posted on 2004-09-02
13
236 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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 250 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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