Domino 9 und frühere Versionen > Entwicklung
Problem mit "Feld History Script"
seerow:
Hallo zusammen,
nach langen stöbern habe ich in der Schatzkiste von eknori ein script gefunden, welches mir die geänderten Felder einen Dokumentes ausgibt.
Ich habe das script etwas an meine Wünsche angepasst. Leider gibt es noch ein kleines Problem. Das script gibt nur das erste geänderte Feld wieder.
Ich möchte aber gerne die Wiedergabe alles geänderten Feldwerte. Wo muss ich da ansetzen?
--- Code: ---Function DocHasChanged(Source As NotesUIDocument) As Integer
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Set uidoc = workspace.CurrentDocument
Dim doc As NotesDocument
Dim session As New NotesSession
Dim whennow As String
Dim whentoday As String
Dim nam As NotesName
Set doc = source.Document
Set nam = New NotesName(session.UserName)
whenNow = Time()
whentoday = Today()
DocHasChanged = False
'Catch the 'List Item Does Not Exist' Error (In case a new item was added to the document)
On Error 120 Goto newitem
'Don't check new documents
If Not source.IsNewDoc Then
'Step through each item on the document
Forall i In doc.items
nm$ = Ucase(i.name)
If nm$ <> "$REVISIONS" And nm$ <> "$UPDATEDBY" And nm$ <> "SAVEOPTIONS" Then ' Filter out specific fields
vl$ = itemValues(nm$)
If vl$ <> i.Text Then
'We have a change.
DocHasChanged = True
'In this case we want to report the change and stop... you could just as easily replace the two ' lines below with other processing code such as recording the changes to a history field, etc.
'------------------------------------------NEW------------------------------------------
Call uidoc.FieldAppendText("fd_printer_historydate", +whentoday+" at "+whennow+ +Chr(10))
Call uidoc.FieldAppendText("fd_printer_historyfield", nm$ +Chr(10))
Call uidoc.FieldAppendText("fd_printer_historyold", vl$ +Chr(10))
Call uidoc.FieldAppendText("fd_printer_historynew", i.Text +Chr(10))
'Call uidoc.FieldAppendText("fd_printer_historynew", "Field "& nm$ &" was changed on "+whentoday+" at "+whennow+" by "+nam.Abbreviated+" from: "& vl$ &" to: "& i.Text+Chr(10))
'------------------------------------------NEW------------------------------------------
Exit Forall
End If
End If
End Forall
End If
Exit Function
newitem:
' This item is new
vl$ = ""
Resume Next
End Function
--- Ende Code ---
koehlerbv:
1. Was für ein grausamer Code - geradezu ein Musterbeispiel, wie man nicht coden sollte.
2. Warum gehst Du nicht im Debugger durch den Code, da siehst Du doch sofort, an welcher Zeile "Ende Gelände" ist.
3. Du verwendest Code, verstehst ihn aber nicht (sonst hättest Du einfachst das Exit Forall gesehen - Das steht sogar im Kommentar kurz davor !). Von solchen Stunts kann man nur absolut abraten !!!
4. Der Code ist nicht vollständig.
Bernhard
seerow:
tja Bernhard wie gesagt,
der code ist nicht von mir sonder von hier -->
http://eknori.dyndns.org/knowledge/devidea.nsf/Alpha/96F26F648AC1ADAE802568550029C0C5?OpenDocument
koehlerbv:
--- Zitat von: seerow am 07.10.04 - 18:02:10 ---der code ist nicht von mir sonder von hier -->
--- Ende Zitat ---
Jaja, das ist mir schon bewusst, hat aber nichts mit meiner Kritik zu tun.
Ulrich brauchte ja irgendeinen Namen für seine Sammlung von Fundstücken aus der weiten Welt des www. Er hat halt "Schatzkiste" genommen. "Wundertüte" wäre vielleicht besser, denn er kann ja nun nicht jedes Fundstück einzeln begutachten oder - vor allem - Jahre später erneut beurteilen.
Ich kann nur immer wieder sagen: Verwendet keinen Code, den Ihr nicht zu hundert Prozent verstanden habt. Passt Code Eurem (Unternehmens-)Stil an. Übernehmt am besten nur die Algorithmen. Aber niemals: Oh, ich weiss nicht, warum - aber es funktioniert !
Bernhard
Axel:
Hi,
der Knackpunkt liegt in der Exit ForAll -Anweisung. Die wird bei der ersten gefundenen Änderung ausgeführt und damit wird die ForAll-Schleife beendet.
....
'------------------------------------------NEW------------------------------------------
Call uidoc.FieldAppendText("fd_printer_historydate", +whentoday+" at "+whennow+ +Chr(10))
Call uidoc.FieldAppendText("fd_printer_historyfield", nm$ +Chr(10))
Call uidoc.FieldAppendText("fd_printer_historyold", vl$ +Chr(10))
Call uidoc.FieldAppendText("fd_printer_historynew", i.Text +Chr(10))
'Call uidoc.FieldAppendText("fd_printer_historynew", "Field "& nm$ &" was changed on "+whentoday+" at "+whennow+" by "+nam.Abbreviated+" from: "& vl$ &" to: "& i.Text+Chr(10))
'------------------------------------------NEW------------------------------------------
Exit Forall <- das muss raus!
End If
End If
End Forall
End If
...
Axel
@Bernhard
Was hast du denn an dem Code auszusetzen? Würde mich mal interessieren.
Navigation
[0] Themen-Index
[#] Nächste Seite
Zur normalen Ansicht wechseln