I need a fresh pair of eyes! Several, in fact!
This script is supposed to find all documents with the PC Configuration form, then spin through the response documents and update any of them that match the info in the form that just got saved. The script finds and updates one response document only. When I debug, I see that after the first response document is updated (doc_Pchange), every other instance where it should be finding a match, AP_Name SHOULD be pulling in the actual value from the response document, but it’s getting the new value (if that has changed) preventing the update. I hope that makes sense. Basically if there are 5 PC Configurations with response documents that need updating, only the first 1 that is found gets changed. Please help. Thanks,
Trish
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
'Written 08/07 by Tricia Pulley, Cadence Technologies
'Revised 11/07 by Tricia Pulley
'IF THIS COMPONENT HAS BEEN UPDATED, CHANGE THE INFORMATION FOR ALL THE
'PC CONFIGURATIONS USING THIS COMPONENT (DIALOG F_ASSPART)
Dim PT_Name As String
Dim PT_Type As String
Dim PT_Cost As String
Dim PT_Vendor As String
Dim PT_Track As String
Dim PT_Default_Today As String
Dim PT_TrackTitle As String
Dim PT_DefaultValue As String
PT_Name = Cstr(doc_Current.PT_Name(0))
PT_Type = Cstr(doc_Current.PT_Type(0))
PT_Cost = Cstr(doc_Current.PT_Cost(0))
PT_Vendor = Cstr(doc_Current.PT_Vendor(0))
PT_Default_Today = Cstr(doc_Current.PT_Default_Today(0))
PT_TrackTitle = Cstr(doc_Current.PT_TrackTitle(0))
PT_DefaultValue = Cstr(doc_Current.DefaultValue(0))
'GET ALL PC CONFIGURATIONS. SPIN THROUGH
'AND GET A COLLECTION OF RESPONSE DOCUMENTS FOR EACH PC CONFIGURATION
'IF THERE IS A MATCH, UPDATE THAT DOCUMENT
'GET THE FIRST PC CONFIG DOCUMENT
Dim LkViewPC As NotesView
Set LkViewPC = db_Current.GetView( "V_CONFIGLOOKUPBYUNID" )
Dim doc_PConfig As New NotesDocument(db_Current)
Set doc_PConfig = LkViewPC.GetFirstDocument
Dim MyUNID As String
MyUNID = Cstr(doc_PConfig.UniversalID)
'IF THERE ARE NO PC CONFIGURATIONS, THEN EXIT SUB
If doc_PConfig Is Nothing Then
Exit Sub
End If
'BEGIN LOOPING THROUGH ALL CONFIG DOCUMENTS
Do While Not doc_PConfig Is Nothing
'GET ALL RESPONSE DOCUMENTS (F_ASSPART) AND SEARCH FOR A MATCH
Dim LkViewP As NotesView
Dim dc_Pcollection As NotesDocumentCollection
Dim doc_PChange As New NotesDocument( db_Current )
Set LkViewP = db_Current.GetView( "V_DIALOGUPDATE" )
Set dc_Pcollection = LkViewP.GetAllDocumentsByKey(MyUNID)
Set doc_PChange = dc_Pcollection.GetFirstDocument
'GET THE OLD VALUES FROM THE FORM TO SEE WHAT CHANGED
Dim Old_PT_Name As String
Dim Old_PT_Type As String
Dim Old_PT_Cost As String
Dim Old_PT_TrackTitle As String
Dim Old_PT_DefaultValue As String
Old_PT_Name = Cstr(doc_Current.PT_OldName(0))
Old_PT_Type = Cstr(doc_Current.PT_OldType(0))
Old_PT_Cost = Cstr(doc_Current.PT_OldCost(0))
Old_PT_TrackTitle = Cstr(doc_Current.PT_OldInfoTitle(0))
Old_PT_DefaultValue = Cstr(doc_Current.PT_OldDefaultValue(0))
'GET THE VALUES FROM THE RESPONSE DOCS TO COMPARE WITH
Dim AP_Name As String
Dim AP_Type As String
Dim AP_Cost As String
Dim AP_TrackTitle As String
Dim AP_DefaultValue As String
If dc_Pcollection.Count > 0 Then
'SPIN THROUGH ALL RESPONSES. IF THERE IS A MATCH, UPDATE IT.
AP_Name = ""
AP_Type = ""
AP_Cost = ""
AP_TrackTitle = ""
AP_DefaultValue = ""
Dim j As Integer
Do While Not doc_Pchange Is Nothing
AP_Name = Cstr(doc_Pchange.PT_Name(0)) '<---This is returning the wrong value!!!
AP_Type = Cstr(doc_Pchange.PT_Type(0))
AP_Cost = Cstr(doc_Pchange.PT_Cost(0))
AP_TrackTitle = Cstr(doc_Pchange.PT_TrackTitle(0))
AP_DefaultValue = Cstr(doc_Pchange.PT_Info(0))
'This section is just to help me see which conditions are true while debugging & will be replaced.
Dim Match_Name As Boolean
If Old_PT_Name = AP_Name Then
Match_Name = True
Else
Match_Name = False
End If
Dim Match_Type As Boolean
If Old_PT_Type = AP_Type Then
Match_Type = True
Else
Match_Type = False
End If
Dim Match_TrackTitle As Boolean
If Old_PT_TrackTitle = AP_TrackTitle Then
Match_TrackTitle = True
Else
Match_TrackTitle = False
End If
Dim Match_Cost As Boolean
If Old_PT_Cost = AP_Cost Then
Match_Cost = True
Else
Match_Cost = False
End If
If Match_Name And Match_Type And Match_TrackTitle And Match_Cost Then
doc_PChange.PT_Name = PT_Name
doc_PChange.PT_Type = PT_Type
doc_PChange.PT_Cost = PT_Cost
doc_PChange.PT_InfoTitle = PT_TrackTitle
doc_PChange.PT_Info = PT_DefaultValue
Call doc_PChange.Save( True, False)
End If
’ If j <> dc_Pcollection.Count Then
AP_Name = ""
AP_Type = ""
AP_Cost = ""
AP_TrackTitle = ""
AP_DefaultValue = ""
Set doc_PChange = dc_Pcollection.GetNextDocument(doc_PChange)
’ End If
Loop
Set doc_PConfig = LkViewPC.GetNextDocument(doc_PConfig)
End If
Loop
End Sub