View help

Hi to all of you,

I have a little problem!

I have some code that is placed on a button on a document, I have to change it so I can place it on a view and it will change all documents where the field modem_a is empty and it will insert the values from another document over the UNID!

I dont know how to go trough the view check the values and how to insert the matching value!

Here is the code that works on a document!

Thank you in advance

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim s As New NotesSession



Dim tempdoc As NotesDocument

Dim uidoc As NotesUIDocument

Dim mbr As Variant

Dim naziv As String

Dim paket As  String

Dim placanje As String

Dim modem As String



Dim view As NotesView



Set db = s.CurrentDatabase

Set uidoc = ws.CurrentDocument

'Set newdoc = uidoc.Document



mbr = uidoc.FieldGetText("jmbg")

naziv = uidoc.FieldGetText("organizacija")

Set View = db.GetView("UgovoriBroj")		' view iz kojeg se izvlače podaci

															' sortirano po UNID dokumenta

			' UNID tekućeg dokumenta

Set tempdoc = view.GetDocumentByKey(mbr,True)



' ako dokument ne postoji unutar   baze ne nastavlja se sa daljnjim slanjem obavijesti

If (tempdoc Is Nothing)  Then

	Msgbox "Ugovor nije pronadjen u bazi ", 0+16,"Greška"

	Exit Sub

End If



brugovor = tempdoc.ugovor_broj(0)

paket = tempdoc.paket(0)

placanje = tempdoc.placanje(0)

modem = Cstr(tempdoc.modem(0))



Call uidoc.FieldSetText("ug_broj",  brugovor)

Call uidoc.FieldSetText("modem_1",Cstr(modem))



If uidoc.FieldGetText("VrstaDokumenta") = "Priključak na Internet" Then 

	Call uidoc.FieldSetText("paket",  paket)

	Call uidoc.FieldSetText("placanje",  placanje)

End If



Call uidoc.Refresh

End Sub

Subject: View help

I won’t bother with any lengthy code here, just the broad outlines.

You should create an agent that runs ‘on selected documents’.

In the view, create a button with formula @Command([ToolsRunMacro]; “NameOfAgent”)

In the agent, you will need this to get the collection of selected documents in the view:

Dim session As New NotesSession

Dim db As NotesDatabase

Dim coll as NotesDocumentCollection

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Set coll = db.UnprocessedDocuments

You now start a loop through the collection:

Set doc = coll.GetFirstDocument

While Not (doc Is Nothing)

… This is where you process your document…

Set doc = coll.GetNextDocument(doc)

Wend

The actual processing is up to you, but shouldn’t pose much of a problem. You will need to check the values and change docs whan needed. Something like this:

If doc.OneValue(0) <> “” Then

Call doc.ReplaceItemValue(“xx”, “yy”)

Call doc.Save(False, False)

End If

If you are going to update the values in the selected documents with values from another document, you will of course need to gran that other document. Preferably by using GetDocumentByKey from a view.

Hope this helps.

// Ken