Domino 9 und frühere Versionen > ND6: Entwicklung
Skript von anderem Button in Skript-Bibliothek
Peter Klett:
Du verstehst sicherlich, dass man nicht mal so eben 500++ Zeilen Code auf Korrektheit prüfen kann. Was mir aufgefallen ist, dass Du im ursprünglichen Code mit oUIDoc As NotesUIDocument arbeitest.
In der Routine der Scriptbibliothek übergibst Du dann ein oUIDoc As NotesDocument, und an der spannendsten Stelle schreibst Du nur [alles identisch].
Wenn es identisch ist, kann es nicht funktionieren, ein NotesDocument ist kein NotesUIDocument. In der aufrufenden Routine übergibst Du auch ein NotesDocument (docAdmin). An der Stelle würde ich nochmal genauer nachsehen.
Mich90:
--- Zitat ---Du verstehst sicherlich, dass man nicht mal so eben 500++ Zeilen Code auf Korrektheit prüfen kann.
--- Ende Zitat ---
Nein, deswegen versuche ich das Problem ja eben möglichst einzugrenzen.
Ich habe nun versucht, den ursprünglichen Button des Katalogdokumentes so umzuschreiben, dass dieser über das Skript funktioniert und bin kläglich gescheitert. Ich sehe aber nicht, wo mein "Fehler" liegt. Es wird alles ausgeführt, aber wie auch zuvor scheint nicht alles zu funktionieren. Irgendetwas wird nicht erledigt. Es muss also an meiner Überführung des Skripts des Buttons in die Skriptbibliothek liegen. Das ist das einzige, was geändert wird (eben das Button-Skript und das oUIDoc im Skript übergeben wird, statt es mit Set oUIDoc = oWS.CurrentDocument zu setzen).
Hier mal die neue Version:
Button ursprünglich:
--- Code: ---Sub Click(Source As Button)
'08.10.09 JE, Conet: neu
'25.12.09 JE, Conet: fldCol_used nach Year/Country-Doku schreiben
'Erzwingt die Neubelegung der Spaltenköpfe für die Budget-Matrix im
'Jahr/Länder-Dokument. In den abhängigen HIER-Dokumenten wird die Daten
'ebenfalls nachgeführt.
Dim oSess As NotesSession
Dim oWS As New NotesUIWorkspace
Dim oDB As NotesDatabase
Dim oView As NotesView
Dim oColl As NotesDocumentCollection
Dim oDoc As NotesDocument
Dim oUIDoc As NotesUIDocument
Dim sCou_ID_new As String
Dim sCou_Name_new As String
Dim sProd_Indications_new As String
Dim sProd_Products_new As String
Dim sProd_Brands_new As String
On Error Goto ErrHandling
'aktuelle DB
Set oSess = New NotesSession
Set oDB = oSess.CurrentDatabase
Set oUIDoc = oWS.CurrentDocument
'Aktualisierung der abhängigen Dokumente
'--------------------------------------------------------------------------
' Kopfdaten (spaltenweise) im Year/Country-Dokument
Dim aVar() As String
iCoumns_n = 48
Redim aVar(1 To iCoumns_n) As String
sCou_ID_new = oUIDoc.FieldGetText("fldCou_ID")
sCou_Name_new = oUIDoc.FieldGetText("fldCou_Name")
sProd_Indications_new = oUIDoc.FieldGetText("fldProd_Indications")
sProd_Products_new = oUIDoc.FieldGetText("fldProd_Products")
sProd_Brands_new = oUIDoc.FieldGetText("fldProd_Brands")
Print "GBD: Column header for " + sCou_Name_new + " will be changed ..."
Set oView = Nothing
Set oColl = Nothing
Set oDoc = Nothing
'CountryYear-Dokument aktualisieren (soweit vorhanden)
Set oView = oDB.GetView("vwLookupAllActiveCountry")
Set oColl = oView.GetAllDocumentsByKey(sCou_ID_new, True)
Set oDoc = oColl.GetFirstDocument
If Not(oDoc Is Nothing) Then
'Strings in Arrays umsetzen, um sie den Listenfeldern zuzuweisen zu können
'H1
For i = 1 To iCoumns_n
aVar(i) = Strtoken(sProd_Indications_new, NL, i)
Next
oDoc.fldMed00H1 = aVar
'H2
Erase aVar
Redim aVar(1 To iCoumns_n) As String
For i = 1 To iCoumns_n
aVar(i) = Strtoken(sProd_Products_new, NL, i)
Next
oDoc.fldMed00H2 = aVar
'H3
Erase aVar
Redim aVar(1 To iCoumns_n) As String
For i = 1 To iCoumns_n
aVar(i) = Strtoken(sProd_Brands_new, NL, i)
Next
oDoc.fldMed00H3 = aVar
oDoc.fldProd_i = Cint(oUIDoc.FieldGetText("fldCol_used"))
Call oDoc.Save(True, True)
End If
'HIER-Dokumente -----------------------------------------------------------
Dim aKey(1) As String
Dim sToken As String
Set oView = Nothing
Set oColl = Nothing
Set oDoc = Nothing
Set oView = oDB.GetView("vwLookupAllActiveHIERColumns")
aKey(0) = sCou_ID_new
'geänderte Indications
For i = 1 To iCoumns_n
aKey(1) = Trim(Str(i))
sToken = Strtoken(sProd_Indications_new, NL, i)
Set oColl = oView.GetAllDocumentsByKey(aKey, True)
If oColl.Count > 0 And i = 1 Then
Print "GBD: ... Indication field in " + Str(oColl.Count) + " " + sCou_Name_new + " documents"
End If
Set oDoc = oColl.GetFirstDocument
While Not(oDoc Is Nothing)
'ändert die Spalten-Dokumente für jedes Media sowie das Summen-Doku der Spalte
oDoc.fldInd_Name = sToken
Call oDoc.Save(True, True)
Set oDoc = oColl.GetNextDocument(oDoc)
Wend
Next
Set oColl = Nothing
Set oDoc = Nothing
'geänderte Products
For i = 1 To iCoumns_n
aKey(1) = Trim(Str(i))
sToken = Strtoken(sProd_Products_new, NL, i)
Set oColl = oView.GetAllDocumentsByKey(aKey, True)
If oColl.Count > 0 And i = 1 Then
Print "GBD: ... Product field in " + Str(oColl.Count) + " " + sCou_Name_new + " documents"
End If
Set oDoc = oColl.GetFirstDocument
While Not(oDoc Is Nothing)
oDoc.fldPro_Name = sToken
Call oDoc.Save(True, True)
Set oDoc = oColl.GetNextDocument(oDoc)
Wend
Next
Set oColl = Nothing
Set oDoc = Nothing
'geänderte Brands
For i = 1 To iCoumns_n
aKey(1) = Trim(Str(i))
sToken = Strtoken(sProd_Brands_new, NL, i)
Set oColl = oView.GetAllDocumentsByKey(aKey, True)
If oColl.Count > 0 And i = 1 Then
Print "GBD: ... Brand field in " + Str(oColl.Count) + " " + sCou_Name_new + " documents"
End If
Set oDoc = oColl.GetFirstDocument
While Not(oDoc Is Nothing)
oDoc.fldBra_Name = sToken
Call oDoc.Save(True, True)
Set oDoc = oColl.GetNextDocument(oDoc)
Wend
Next
Print "GBD: Refreshing has been successful complited"
m3:
Ende:
Exit Sub
ErrHandling:
Msgbox "GBD: Error Refresh Catalog Country: Line " + Cstr(Erl) + " Message: " + Error
Err = 0
Resume Ende
End Sub
--- Ende Code ---
Hier der "neue Button" mit dem Skriptaufruf:
--- Code: ---Sub Click(Source As Button)
Dim oWS As New NotesUIWorkspace
Dim oDB As NotesDatabase
Dim oView As NotesView
Dim oUIDoc As NotesUIDocument
'aktuelle DB
Set oSess = New NotesSession
Set oDB = oSess.CurrentDatabase
Set oUIDoc = oWS.CurrentDocument
'aktuelle DB
Set oSess = New NotesSession
Set oDB = oSess.CurrentDatabase
Set oUIDoc = oWS.CurrentDocument
Call UpdateDocuments(oUIDoc)
End Sub
--- Ende Code ---
Und hier die Skriptbibliothek:
--- Code: ---Sub UpdateDocuments(oUIDoc As NotesUIDocument)
'Dim oSess As NotesSession
Dim oWS As New NotesUIWorkspace
Dim oDB As NotesDatabase
Dim oView As NotesView
Dim oColl As NotesDocumentCollection
Dim oDoc As NotesDocument
Dim sCou_ID_new As String
Dim sCou_Name_new As String
Dim sProd_Indications_new As String
Dim sProd_Products_new As String
Dim sProd_Brands_new As String
On Error Goto ErrHandling
'aktuelle DB
Set oSess = New NotesSession
Set oDB = oSess.CurrentDatabase
'Aktualisierung der abhängigen Dokumente
'--------------------------------------------------------------------------
' Kopfdaten (spaltenweise) im Year/Country-Dokument
Dim aVar() As String
iCoumns_n = 48
Redim aVar(1 To iCoumns_n) As String
sCou_ID_new = oUIDoc.FieldGetText("fldCou_ID")
sCou_Name_new = oUIDoc.FieldGetText("fldCou_Name")
sProd_Indications_new = oUIDoc.FieldGetText("fldProd_Indications")
sProd_Products_new = oUIDoc.FieldGetText("fldProd_Products")
sProd_Brands_new = oUIDoc.FieldGetText("fldProd_Brands")
Print "GBD: Column header for " + sCou_Name_new + " will be changed ..."
Set oView = Nothing
Set oColl = Nothing
Set oDoc = Nothing
'CountryYear-Dokument aktualisieren (soweit vorhanden)
Set oView = oDB.GetView("vwLookupAllActiveCountry")
Set oColl = oView.GetAllDocumentsByKey(sCou_ID_new, True)
Set oDoc = oColl.GetFirstDocument
If Not(oDoc Is Nothing) Then
'Strings in Arrays umsetzen, um sie den Listenfeldern zuzuweisen zu können
'H1
For i = 1 To iCoumns_n
aVar(i) = Strtoken(sProd_Indications_new, NL, i)
Next
oDoc.fldMed00H1 = aVar
'H2
Erase aVar
Redim aVar(1 To iCoumns_n) As String
For i = 1 To iCoumns_n
aVar(i) = Strtoken(sProd_Products_new, NL, i)
Next
oDoc.fldMed00H2 = aVar
'H3
Erase aVar
Redim aVar(1 To iCoumns_n) As String
For i = 1 To iCoumns_n
aVar(i) = Strtoken(sProd_Brands_new, NL, i)
Next
oDoc.fldMed00H3 = aVar
oDoc.fldProd_i = Cint(oUIDoc.FieldGetText("fldCol_used"))
Call oDoc.Save(True, True)
End If
'HIER-Dokumente -----------------------------------------------------------
Dim aKey(1) As String
Dim sToken As String
Set oView = Nothing
Set oColl = Nothing
Set oDoc = Nothing
Set oView = oDB.GetView("vwLookupAllActiveHIERColumns")
aKey(0) = sCou_ID_new
'geänderte Indications
For i = 1 To iCoumns_n
aKey(1) = Trim(Str(i))
sToken = Strtoken(sProd_Indications_new, NL, i)
Set oColl = oView.GetAllDocumentsByKey(aKey, True)
If oColl.Count > 0 And i = 1 Then
Print "GBD: ... Indication field in " + Str(oColl.Count) + " " + sCou_Name_new + " documents"
End If
Set oDoc = oColl.GetFirstDocument
While Not(oDoc Is Nothing)
'ändert die Spalten-Dokumente für jedes Media sowie das Summen-Doku der Spalte
oDoc.fldInd_Name = sToken
Call oDoc.Save(True, True)
Set oDoc = oColl.GetNextDocument(oDoc)
Wend
Next
Set oColl = Nothing
Set oDoc = Nothing
'geänderte Products
For i = 1 To iCoumns_n
aKey(1) = Trim(Str(i))
sToken = Strtoken(sProd_Products_new, NL, i)
Set oColl = oView.GetAllDocumentsByKey(aKey, True)
If oColl.Count > 0 And i = 1 Then
Print "GBD: ... Product field in " + Str(oColl.Count) + " " + sCou_Name_new + " documents"
End If
Set oDoc = oColl.GetFirstDocument
While Not(oDoc Is Nothing)
oDoc.fldPro_Name = sToken
Call oDoc.Save(True, True)
Set oDoc = oColl.GetNextDocument(oDoc)
Wend
Next
Set oColl = Nothing
Set oDoc = Nothing
'geänderte Brands
For i = 1 To iCoumns_n
aKey(1) = Trim(Str(i))
sToken = Strtoken(sProd_Brands_new, NL, i)
Set oColl = oView.GetAllDocumentsByKey(aKey, True)
If oColl.Count > 0 And i = 1 Then
Print "GBD: ... Brand field in " + Str(oColl.Count) + " " + sCou_Name_new + " documents"
End If
Set oDoc = oColl.GetFirstDocument
While Not(oDoc Is Nothing)
oDoc.fldBra_Name = sToken
Call oDoc.Save(True, True)
Set oDoc = oColl.GetNextDocument(oDoc)
Wend
Next
Print "GBD: Refreshing has been successful complited"
m3:
Ende:
Exit Sub
ErrHandling:
Msgbox "GBD: Error Refresh Catalog Country: Line " + Cstr(Erl) + " Message: " + Error
Err = 0
Resume Ende
End Sub
--- Ende Code ---
Wie gesagt, bis darauf, dass ich oUIDoc im Skript übergebe statt es zu setzen, habe ich nichts geändert. Ich arbeite jetzt auch im Skript mit NotesUIDocument.
Da sonst nichts geändert wurde, muss der Fehler doch in der Überführung vom alten Skriptbutton in den neuen + Bibliothek liegen, oder? :-:
klaussal:
Ich habe auch nicht wirklich "Lust" (und auch keine Zeit), das ganze Script Zeile für Zeile zu untersuchen.
Ich bin der Meinung, dass das Problem bei richtiger Anwendung des Debuggers zu lösen sein sollte.
Axel:
Du wirst hier kaum jemand finden, der Zeit hat sich durch den Code zu kämpfen und ihn auf irgendwelche Fehler zu untersuchen.
Schau dir den Code mit dem Debugger an und prüfe ob die Variablen die Werte enthalten, die sie zu dem entsprechenden Zeitpunkt haben sollen.
Du kannst den Code auch in einzelne Abschnitt unterteilen. D.h. führe ihn bis zu einem bestimmten Punkt aus und schau die das Ergebnis an ob es deinen Vorstellungen entspricht. Wenn ja, das häng das nächste Stück dran und teste wieder. So hangelst du dich dann Stück für Stück weiter.
Wenn dabei konkrete Fragen auftauchen sind wir gerne bereit zu helfen.
Axel
ata:
... der Code im neuen Button macht nicht wirklich Sinn - du dimensionierst Dinge, die du gar nicht brauchst.
Eigentlich wärst du mit ...
Dim oWS As New NotesUIWorkspace
Call UpdateDocuments( oWS.CurrentDocument )
... ausreichend bedient.
In deiner Funktion initialisiert du die aktuelle Datenbank über eine neue Session-Instanz. Das würde ich über das übergebene UIDoc machen...
Set oDB = UIdoc.Document.ParentDatabase
... der Rat der Vorredner ist gesetzt - nimm den Debugger - damit siehst du effizient, was wo nicht tickt... ;)
Toni
Navigation
[0] Themen-Index
[#] Nächste Seite
[*] Vorherige Sete
Zur normalen Ansicht wechseln