List of Departments within NAB

Hello All.

This is probably an easy enquiry for most of you, but I was just wondering whether anyone could help me, or perhaps provide me with some sample LotusScript please?

What I want to do is that I need to have some script that can be run from a button to retreive all departments that have been used in a NAB.

Remove any duplicates and then put this list into a field on a form so it can be referenced by another formula.

I know this sounds easy but I have tried a few things and they don’t seem to work as I would expect and script is really not my forte but I need something more robust than formula for this lookup to give the code increased longevity.

Can anyone help please?

Subject: List of Departments within NAB

you would need to create a view in the NAB to display the departments then do a dblookup or dbcolumn to retrieve the values for your button code.

Subject: List of Departments within NAB

I’m going to offer two solutions. The first one’s viability depends on whether or not this view exists in the standard template (ours has been customized quite a bit, and I don’t know if it has changed).

Open NAB and look for a view called People\By Department. If you have this view (if it’s not something we added to our address book template), then you can simply use @Unique and @DbColumn to get a unique list of departments.

Subject: RE: List of Departments within NAB

This is LS code to do the same. It’s off the top of my head, so test it:

sub GetList

Dim db as NotesDatabase

Dim view as NotesView

dim currdoc as Notesdocument

dim uiwk as New NotesUIWorkspace

dim uidoc as NotesUIDocument

dim s as new notessession

dim vc as notesviewentrycollection

dim entry as notesviewentry

set uidoc = uiwk.CurrentDocument

set currdoc = uidoc.Document

set db = s.CurrentDatabase

set view = db.Getview(“People\By Department”) 'Could be any view with the documents you want. You would then use the field value on the document and NOT the columValue

set vc = view.AllEntries

dim entryArray(0 to vc.Count - 1)

dim x as integer

x = 0

set entry = vc.GetFirstEntry()

Do While (not entry is Nothing)

entryArray(x) = entry.ColumnValues(0)

x = x + 1

Loop

ArrayUnique(entryArray, 5)

currdoc.fieldname = entryArray

call currdoc.save(true, false)

call uidoc.refresh()

erase entryArray 'to recover the storage

set currdoc = nothing

set uidoc = nothing

set entry = nothing

set vc = nothing

set view = nothing

set db = nothing

set uiwk = nothing

set s = nothing

end sub

Subject: RE: List of Departments within NAB

Thank you all for your responses.

Joel, I’m pretty certain that the People/By Department view would have been added your end because I personally haven’t seen that view before in a NAB and I don’t have the option to add that view in, because I’m want this code to work in a bog standard environment with any NAB.

Your code looks like it’s in the right direction, (and given I write this before I have tested it yet), but I don’t see how you are picking up the list of department values and removing the duplicates.

I will post back here and apologise if it does work but I don’t think it will do exactly what I need.

Although, as I said, I am grateful for your help.

Essentially what I think I need to do is the following…

In Script : -

Do search for all forms or just person forms that contain the department field.

Put into document collection.

Make array with document collection.

Do evaluate @unique or equivalent on the department field list and then pop the remaining values into the field on the form.

It’s just as I said, I’ve tried a few ways to do this and it doesn’t work as I would expect.

If it was just going to be used in our environment then I would just create a new view and do an @dbcolumn but I can’t do that.

Any ideas?

Subject: RE: List of Departments within NAB

this should create the unique array for you. I don’t have it resulting to anything but if you step through the debugger you can see the list grow and the check for duplicates.

Sub Initialize

Dim ns As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim dept As String

Dim depts() As String

Redim Preserve depts(1 To 1)

Dim count As Integer

count = 1

Set db = ns.CurrentDatabase

Set view = db.GetView("People")

Set doc = view.GetFirstDocument

While Not doc Is Nothing

	dept = doc.Department(0)

	If dept <> "" Then

		If depts(1) = "" Then

			depts(1) = dept

			Goto skip

		End If

		Forall d In depts

			If d = dept Then

				Goto skip

			End If

		End Forall

		count = count + 1

		Redim Preserve depts( 1 To count)

		depts(count ) = dept

	End If

skip:

	Set doc = view.GetNextDocument(doc)

Wend

End Sub

Subject: RE: List of Departments within NAB

Thanks Paul.

Your code does exactly what I was looking for and I now understand where I was going wrong.

Many Thanks.