New - B! Am I doing this right?

Hey all,

I have a dialog list (called Divisions) where the user will select an option.

Based on the option selected, i would like it to gather the information for that option from another database…

Can anyone help with my code as im new to coding lotusscript.

Sub Postopen(Source As Notesuidocument)

Dim ws As New NotesUIWorkspace

Dim divisonsdoc As NotesDocument

Dim divisionsname As String



'Getting the users to select a division

Dim db As NotesDatabase

Set db  = session.currentdatabase

Divisions = divisionsList(db.Search({Form = "Aset"}, "Divisons", 0))

If Ubound(Divisions) = 0 Then

	divisionsname = Strright(Divisions(0), "|")

Else

	Dim export As NotesDocument

	Set export = dbcreatedocument

	'List of all the divisions for the user to select

	export.divisions = divisions

	export.divisions = divisions(0)

	x = ws.DialogBox("(dlgCustomExport)", True, True, False, False, False, False, "Choose Division", export, False, False)

	If x = False Then divisonname = ""Else divisionname = export.divisons(0)

End If

If divisionsname = "" Then Msgbox "Sorry an error was cause. Please try again...":

Exit Sub

End Sub

Any help given will be grateful.

Thank you

Gem x

Subject: New - B! Am I doing this right?

Hi there,

Welcome to Lotus Script!

In this line…

Divisions = divisionsList(db.Search({Form = “Aset”}, “Divisons”, 0))

What is divisionslist?

I assume Divisions is a notesdocumentcollection object because you are attempting to use db.search. db.search returns as notesdocumentcollection rather than a list of strings.

I suggest the following…

  • Open the ‘other database’ by declaring a new database object and using notesdatabase.open or notesdatabase.openbyreplicaid

  • dim Divisions as notesdocumentcollection

  • set Divisions = ‘otherdb’.search…

loop through the documents in your collection (see while not) and put your ‘value’ into an array

Then you can set the divisions field on the export document to your list and open your dialogbox.

Also, when i write script i find it really useful to write all the comments for my code first. Then it is simply a case of filling in the code around the comments.

I hope this helps.

Subject: RE: New - B! Am I doing this right?

Hey Stephen,

Thanks for helping me out…

Ive altered my code and was wondering whether you could me a little more…?

At the moment i keep getting compiling errors ‘Illegal parenthesized reference: DIVISIONS’ on the following lines (*)

Sub Postopen(Source As Notesuidocument)

Dim ws As New NotesUIWorkspace

Dim s As New NotesSession

Dim divisionsname As String

Dim Divisions As NotesDocumentCollection



'Getting the users to select a division

Dim dbExternal As NotesDatabase

Set dbExternal = s.GetDatabase("Domapps1/Syy", "IT\AssTrac.nsf")

Dim viewExternal As NotesView

Set viewExternal = dbExternal.GetView("va_ec")

Divisions = (db.Search({Form = "IT\AssTrac.nsf"}, "Divisons", 0))

If Ubound(Divisions) = 0 Then

	divisionsname = Strright(Divisions(0), "|")  *

Else

	Dim export As NotesDocument

	Set export = dbcreatedocument

	'List of all the divisions for the user to select

	export.divisions = divisions		

	export.divisions = divisions(0) *

	x = ws.DialogBox("(dlgCustomExport)", True, True, False, False, False, False, "Choose Division", export, False, False)

	If x = False Then divisonsname = ""Else divisionsname = export.divisons(0)

End If

If divisionsname = "" Then Msgbox "Sorry an error was caused. Please try again...":

Exit Sub

End Sub

Any ideas? Sorry to be a pain.

Thanks

Gem

Subject: RE: New - B! Am I doing this right?

Hi there,

No worries…

You seem to be a little confused with how to use some of the built-in methods… Which is no surprise if you are new to Lotus Script :slight_smile: I’ll try to write this code for you…Obviously you might need to change some field names etc…

dim ws as new notesuiworkspace

dim s as new notessession

dim db as notesdatabase

dim divisionname as string

dim divisioncoll as notesdocumentcollection

dim divisiondoc as notesdocument

dim divisions() as string

dim dbexternal as notesdatabase

REM Get current database

set db = s.currentdatabase

REM Get ‘other’ database

set dbexternal = new notesdatabase(“DomApps1/Syy”,“IT\AssTrac.nsf”)

if not dbexternal.isopen then

 msgbox "Cannot open database. Exiting code",48,"Error"

 continue = false

 exit sub

end if

dim viewexternal = dbexternal.getview(“va_ec”)

REM Get collection of documents from external database

set divisioncoll = dbexternal.search({Form=“”},nothing,0)

if divisioncoll.count = 0 then

 msgbox "No external database documents found. Exiting code",48,"Error"

 continue = false

 exit sub

end if

REM Loop through documents and build an array of values for the user to select

set divisiondoc =divisioncoll.getfirstdocument

dim i as integer

while not(divisiondoc is nothing)

 REM Add values to array

r edim preserve divisions(i)

 divisions(i) = divisiondoc.fieldvalue(0) 'change fieldvalue for the name of the field that holds the value

 i = i + 1

 set divisiondoc = divisioncoll.getnextdocument(divisiondoc)

wend

REM Give the user a list of divisions

value = ws.prompt(PROMPT_OKCANCELLIST,“divisions list”,“Please select from the divisions list”,divisions(0),divisions)

REM exit code if the user didn’t select a value

if value = “” then

 msgbox "No value selected.Exiting code",48,"Error"

 continue = false

 exit sub

end if

REM Do here what you want with value