Go Premium for a chance to win a PS4. Enter to Win

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

Script Mod

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
schmad01
Asked:
schmad01
  • 7
  • 6
1 Solution
 
Sjef BosmanGroupware ConsultantCommented:
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
 
schmad01Author Commented:
I will try next week and update you. Thanks alot.
0
 
schmad01Author Commented:
Tried it, but filleddate1 field is still blank.  It is a time-date field set as computed when composed.
0
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.

 
Sjef BosmanGroupware ConsultantCommented:
Why computed when composed? And did you save the document after modifying the field?
0
 
schmad01Author Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
schmad01Author Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
schmad01Author Commented:
I tried it in different earlier positions. Still nothing.  Strange.
0
 
schmad01Author Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
schmad01Author Commented:
You got it. Thanks, Sjef.
0
 
Sjef BosmanGroupware ConsultantCommented:
:)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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