Domino 9 und frühere Versionen > ND6: Entwicklung
LotusScript: Dokumente durchsuchen und Feldinhalte ändern
shaolinh:
Hallo!
Ich bin neu in LotusScript-Programmierung und habe einige Anfängerschwierigkeiten.
Das Skript soll folgendes leisten:
Einige Feldinhalte (country, city, companyName) des ausgewählten Dokumentes sollen ausgelesen und durch Interaktion mit einem User (Prompt) verändert werden können.
Als nächstes müssen einige andere Dokumente, die die alten Feldinhalte (ccc-Feld) aufweisen durch die neuen Inhalt ersetzt werden.
Ein Beispiel für ein CCC-Feld:
Deutschland - Berlin - Firma A
England - London - Firma B
Ich bin auf zwei Probleme gestoßen:
1. Nach der Eingabe der neuen Daten werden die Feldinhalte nicht aktualisiert. Mit NotesUIDocument AutoReload bin ich leider nicht weitergekommen
2. Anscheinend wird beim Durchsuchen des oldCCC-Feldes nur der erste Eintrag genommen, am Bsp. oben Deutschland - Berlin - Firma A. Es soll aber die komplette CCC-Liste durchgegangen werden. Ich denke hier muss ich eine Schleife verwenden und das oldCCC-Feld durchgehen?
Wäre nett, wenn mir jemand weiterhelfen kann. Ich weiß, dass der Code nicht gerade effizient ist. Für weitere Tipps wäre ich auch dankbar!
Hier das Skript:
Sub Initialize
On Error Goto ERRORHANDLER
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim dbTarget As NotesDatabase
Dim docContact As NotesDocument
Dim docNextContact As NotesDocument
Dim docLocation As NotesDocument
Dim uiDocLocation As NotesUIDocument
Dim vItems As Variant
Dim flag As Boolean
Dim iCount As Integer
Dim collectionContact As NotesDocumentCollection
Dim collectionLocation As NotesDocumentCollection
Dim oldCity As Variant
Dim oldCountry As Variant
Dim oldCompanyName As Variant
Dim oldCCCValue As String
Dim oldCCC As Variant
Dim newCity As Variant
Dim newCountry As Variant
Dim newCompanyName As Variant
Dim newCCCValue As String
Dim newCCC As Variant
Dim strItemEntryContact As Variant
Set db = session.CurrentDatabase
Set collectionLocation = db.UnprocessedDocuments 'selektiertes Dokument aus einer Ansicht -> nur ein Dokument darf ausgewählt werden
Set collectionContact = db.AllDocuments 'Alle potentiellen Dokumente der Kontaktlisten
'Sichere die alten country, city, companyName des Standortes
Set docLocation = collectionLocation.GetFirstDocument
oldCountry = docLocation.GetItemValue("country")
oldCity= docLocation.GetItemValue("city")
oldCompanyName = docLocation.GetItemValue("companyName")
oldCCCValue = oldCountry(0) &" - " & oldCity(0) & " - " & oldCompanyName(0)
'Set uiDocLocation = workspace.CurrentDocument 'uidoclocation is nothing
'uiDocLocation.AutoReload = True
flag = workspace.DialogBox("ChangeLocCCC",True,True,False,True,False,False,"Change Location")
If flag = False Then Exit Sub
Call workspace.Prompt(PROMPT_OK,"Starten...","OK")
newCountry = docLocation.GetItemValue("country") ' PROBLEM: Es werden weiterhin die alten Werte genommen -> keine Ersetzung
newCity= docLocation.GetItemValue("city")
newCompanyName = docLocation.GetItemValue("companyName")
newCCCValue = newCountry(0) &" - " & newCity(0) & " - " & newCompanyName(0)
Call workspace.Prompt(PROMPT_OK,"check ccc",newCompanyName(0))
icount = 0
'Durchsuche alle Kontakt-Dokumente und ersetze den ccc-Wert des alten Standortes durch den neuen
Set docContact = collectionContact.GetFirstDocument
While Not (docContact Is Nothing)
icount = icount + 1
Set docNextContact = collectionContact.GetNextDocument(docContact)
oldCCC = docContact.GetItemValue("ccc") 'Anscheinend wird nur erster String genommen? Mit einer Schleife durchgehen?
'flag = workspace.Prompt(PROMPT_YESNO,Cstr(icount),oldCCC(0))
'If flag = 0 Then Exit Sub
If Instr (oldCCC(0),oldCCCValue) <> 0 Then 'substring von oldcccvalue in oldccc
'newCCC = ReplaceSubString(oldCCC(0),oldCCCValue,newCCCValue)
newCCC = Replace(oldCCC(0),oldCCCValue,newCCCValue)
Call docContact.ReplaceItemValue ("ccc",newCCC) 'replace mit mehreren standortzugehörigkeiten eines Kontaktes klappt nicht, nur erster eintrag wird ersetzt?
'evtl. oldCCC Schleife durchgehen??
Call docContact.Save(False, False)
End If
Set docContact = docNextContact
Wend
EXIT_SCRIPT:
Exit Sub
ERRORHANDLER:
Msgbox "Error: " & Err & " - " & Error$ & Chr(10) & Chr(10)_
& "Line: " & Erl & Chr(10), _
48, "An error occured"
Resume EXIT_SCRIPT
End Sub
dirk_2909:
--- Code: --- flag = workspace.DialogBox("ChangeLocCCC",True,True,False,True,False,False,"Change Location")
--- Ende Code ---
Hie musst Du die Felder, die ändern möchtest "initialiseren" und vorher ein Dokument erzeugen, übder das Du temorär die Werte änderst:
Ser docDlg = db.CreateDocument
call docDlg.ReplaceItemValue( "City" , oldCity )
...
...
flag = workspace.DialogBox("ChangeLocCCC",True,True,False,True,False,False,"Change Location" , docDlg )
if flag Then
if docDlg.GetItemValue( "City" )( 0 ) <> "" and docDlg.GetItemValue( "City" )( 0 ) <> oldCity Then
newCity = docDlg.GetItemValue( "City" )(
end if
.....
end if
shaolinh:
Hallo,
erstmal vielen Dank für den Tipp. Das hat funktioniert. Ich habe den Code etwas modifiziert. Nun habe ich ein weiteres Problem, wo ich nicht weiterkomme.
Am gleichen Standort funktioniert das Skript der Standortänderung und im nächsten Augenblick funktioniert es nicht mehr. Das Skript bricht auch an einer unterschiedlichen Stelle ab.
Ich bekomme folgende Fehlermeldung:
Notes Error – Eintrag im Index nicht gefunden (SiteContactsByName)
Line 103
wäre super, wenn mir da jmd weiterhelfen kann.
Hier ein Auszug des Codes:
'Suche die entsprechenden Kontakte, deren alter CCC-Wert für den Standort durch den neuen CCC-Wert ersetzt werden soll
Set view = db.GetView("sitecontactsbyname")
If view.IsCategorized Then
Set nav = view.CreateViewNavFromCategory(oldCCCValue)
Else
Call workspace.Prompt(PROMPT_OK,"Starten...","View not categorizes")
Exit Sub
End If
Set docContactEntry = nav.GetFirstDocument
'Gehe alle Kontakte für den Standort durch und ersetze den alten CCC-Wert durch den neuen CCC-Wert
While Not (docContactEntry Is Nothing)
Set docContact = docContactEntry.Document
Set docNextContactEntry = nav.GetNextDocument(docContactEntry) 'Line 103
contactCCC = docContact.CCC
Set tmp = New NotesDocument(db)
tmp.CCC = contactCCC
formula = |@Trim(@Replace(CCC;"| & oldCCCValue & |";"| & newCCCValue & |"))|
Stop
erg = Evaluate(formula,tmp)
docContact.CCC = erg
Call docContact.Save(True,True)
Stop
Set docContactEntry = docNextContactEntry
Wend
m3:
a) Neue Frage - neuer Thread. Bitte nächstes mal beachten. ;)
b) Nachdem Du nicht den ganzen Code von "(SiteContactsByName)" angibst, wäre es schon praktisch, wenn Du die Zeile 103 entsprechend markieren könntest. Sonst wird es etwas schwer, Dir zu helfen. /me holts sich erst mal einen Kaffee. Sorry for the noise.
klaussal:
Durch die Änderung des CCC wird evtl. die View durcheinander gewirbelt und der GetNext funzt nicht mehr.
Navigation
[0] Themen-Index
[#] Nächste Seite
Zur normalen Ansicht wechseln