LSXLC & Simple Script Problem

I am encountering an issue (expected End) with our new script. This script was designed to access a DB2 table and(email address column) to fetch email addresses then send. I am encountering a script error at the Call docMemo… and Next lines. Is that Call docMemo… correct? Thanks team…

Dim lccon As New LCConnection(“CUSDB2”)

Dim flCustomer As New LCFieldlist(100)

Dim fldEmail As LCField

Dim lngCount As Long

Dim lngInd As Long

dim session as notesSession

dim dB as notesDataBase

dim docMemo as notesDocument

set session = new notesSession

set dB = session.currentDataBase

lccon.Metadata = “SAMPLE.EMAILS”

lccon.Fieldnames = “CEMAIL”

lccon.Connect

Call lccon.Select(Nothing, 1, flCustomer)

Set fldEmail = flCustomer.Lookup(“CEMAIL”)

lngCount = lccon.Fetch(flCustomer, 1, 100)

For lngInd = 1 to lngCount

Do Until lngCount = 0

recipients = ArraySlice(fldEmail.Value, 0, lngCount - 1)

Call docMemo.ReplaceItemValue(“BlindCopyTo”, recipients)

Call docMemo.Send False

Next

lngCount = lccon.Fetch(flCustomer, 1, 100)

Loop

Subject: LSXLC & Simple Script Problem

Michael,

Stupid question, but is this the complete script? Where do you define what docMemo is?

Brandt

Subject: RE: LSXLC & Simple Script Problem

This was not the entire script (but almost!)… and your ? was not stupid. :slight_smile: As a matter of fact, it might not be defined! The only missing pieces are error handling and a couple messageboxes. Excuse my ignorance here… but where/what should be set for DocMemo (assuming dim docMemo…).

Subject: RE: LSXLC & Simple Script Problem

This is the exact reason I turn on Option Declare / explicit in all my scripts - helps find the problem alot sooner. I would be surprised if the script compiled the way it was posted.

Subject: RE: LSXLC & Simple Script Problem

Add “Option Declare / Explicit” in the [OPTIONS] section? You are correct… it did not save in the current state? I now know that some dim/set + For were missing. I have corrected the original posting. Here is the current version…

note: it seems that the “CUSDB2” connection (if initiated -w- client-side action button) might have issues with DECS. I wonder if a DCR or just entering the LC line with Db, name, password would work?

Dim lccon As New LCConnection(“CUSDB2”)

Dim flCustomer As New LCFieldlist(100)

Dim fldEmail As LCField

Dim lngCount As Long

Dim lngInd As Long

dim session as notesSession

dim dB as notesDataBase

dim docMemo as notesDocument

set session = new notesSession

set dB = session.currentDataBase

lccon.Metadata = “SAMPLE.EMAILS”

lccon.Fieldnames = “CEMAIL”

lccon.Connect

Call lccon.Select(Nothing, 1, flCustomer)

Set fldEmail = flCustomer.Lookup(“CEMAIL”)

lngCount = lccon.Fetch(flCustomer, 1, 100)

For lngInd = 1 to lngCount

Do Until lngCount = 0

recipients = ArraySlice(fldEmail.Value, 0, lngCount - 1)

Call docMemo.ReplaceItemValue(“BlindCopyTo”, recipients)

Call docMemo.Send False

Next

lngCount = lccon.Fetch(flCustomer, 1, 100)

Loop

Subject: Call docMemo.Send

It had a problem with “Call docMemo.Send False”… dropped the false and it appeared fine. What is the purpose of the False?

Subject: RE: Call docMemo.Send

“False”, in this instance, means “don’t store the form in the document”. But that’s not the issue here. It’s a matter of syntax. There are two ways to call a method in LotusScript - one that explicitly uses the “Call” keyword and requires parentheses around any arguments, and one that leaves out both “Call” and the parentheses.

Call docMemo.Send(False)

docMemo.Send False

Personally, I find the first style much more readable/maintainable, especially where multiple arguments are involved.

Subject: RE: Call docMemo.Send

Thanks (as always) Stan… good to know. I grabbed the “Call docMemo…” from this forum. It had the False w/o (). I now know better. Similar to that Wikipedia entry… :slight_smile:

I did try and run the script (before seeing your post) but ran into a illegal use of ArraySlice dialog right after pressing the action button. Any thoughts?

Subject: RE: Call docMemo.Send

I think you’re missing some code – ArraySlice is not a native function as far as I know (unless it’s part of the LC LSX). It looks like it’s essentially the equivalent of @Subset, but I’ve never run into it. Could it be a local custom function?

Subject: RE: Call docMemo.Send

Good question Stan! You got me… this bit o’ code came from Andre Guirard. I just know to “Dim recipients As Variant”… but still get a “variable not declared: ARRAY SLICE” error on the “recipients=ArraySlice(…” line. I feel like I’m close… one line away. I call a connection on the 1st line or so… was a DECS connection. It sounds like that will not work if the client is clicking a button (even if accessing server Db). I’m hoping that a DCR is another option… understand that RunOnServer might be another. I’m just not familiar with this option or how to retro this script.

Subject: RE: Call docMemo.Send

Okay, then, it seems like what you need is ArraySlice(). If it does what I think it does, then this should do it:

Function ArraySlice(inArray As Variant, startIndex As Integer, endIndex As Integer) As Variant

If Not IsArray(inArray) Then

	ArraySlice = inArray

Else

	If Ubound(inArray) < endIndex Then

		endIndex = Ubound(inArray)

	End If

	If Lbound(inArray) > startIndex Then

		startIndex = LBound(inArray)

	End If

	Dim outIndex As Integer

	outIndex = 0

	Dim i As Integer

	Dim topCount As Integer

	topCount = (endIndex - startIndex)

	Dim outArray() As Variant

	Redim outArray(topCount)

	For i = startIndex To endIndex

		outArray(outIndex) = inArray(i)

		outIndex = outIndex + 1

	Next

	ArraySlice = outArray

End If

End Function

Subject: RE: Call docMemo.Send

Wow… thanks Stan and Andre. This is heavy… wasn’t aware that the ArraySlice would be so involved. Also, for the benefit of others, I am posting a link back to Andre’s posting with the ArraySlice reference (please see below).

Update: I included Stan’s ArraySlice function and all seemed well. The Yes/No messagebox pops up then a “Error Loading Product Object” dialog appeared. Any ideas what this is? I’ll search the forum now. JUst searched… many postings related to Db connections and local vs. server runs. Since this action is user-initiated, I’m hoping that a DCR would work (if DECS does not). I’m placing some messageboxes in various spots to see where the problem is. Update #2… it seems to stop at the Dim lcconn As New Connection…" line. Sounds like it is unable to get to the DECS connection. Wonder if DCR would work…

note: I have seen many postings here re: client-initiated scripts to RDMS’, etc. I understand that there may be issues using a DECS/LEI connection if not run by the server (e.g. scheduled). I have also heard about RunOnServer but am not the expert with how to use this in conjunction with an action button.

https://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/22bc2b039b1e3c1b85256f8f0011f17f?OpenDocument

Subject: RE: Call docMemo.Send

I sent you email with a link to an article – here it is again: Off-loading Lotus Enterprise Integration tasks to the server .

Code running on the client cannot access data in a connection document on the server – if for no other reason, because the DEC administrator database is not open access for all users (if you have any sense). So they lack the access to read the data from the connection document, and the LC LSX doesn’t know which server to look at to find the information anyway.

For this to work the code would have to run on the server – not just be stored on the server.

Subject: RE: Call docMemo.Send

Thanks for the response (I did get your email). We’re looking at other options… scheduled agent to retrieve addresses, etc. We have no issue with scheduled agents, etc.

Subject: RE: Call docMemo.Send

As I said in the original post that you took this code from, “…ArraySlice is a custom function to return a designated subset of an array; the implementation is left as an exercise for the reader.”

It doesn’t appear that you’re at the point in your LotusScript career where you could write this yourself. Here’s my untested code:

Function ArraySlice(anArray, Byval iPosStart As Integer, Byval iPosEnd As Integer) As Variant

Redim result(0 to iPosEnd-iPosStart) As Variant ’ or String, which is more efficient if you know you’ll only be handling strings

Dim iInd As Integer

For iInd = iPosStart to iPosEnd

result(iInd-iPosStart) = anArray(iInd)

Next

ArraySlice = result

End Function

Not the most efficient, but it should get the job done.

Subject: RE: LSXLC & Simple Script Problem

Why do you have a Next statement? Where’s the corresponding For?

Subject: RE: LSXLC & Simple Script Problem

Thanks Andre… some of our code came from one of your examples (many months ago). It seems we took it literally… and missed some pieces like “dim docMemo…”, etc. I just updated the original posting to include the missing For statement (For lngInd = 1 to lngCount). It was overwritten when the BCC: code was used (vs. the original that placed in TO:). Our goal was to create the button “Send Newsletter” with this script and have it fetch addresses from DB2 then email. Does this fetch grab and send in batches of 100 or grab all addresses then send? We have encountered the field limit for TO: and had to split up. I’m hoping it grabs/sends in these smaller chunks. Thanks for any advice…

On another note… what about creating a customer email group in the directory that is updated from DB2 vs. pulling on demand? Issue… it would be 3K+ addresses… any issues here re: performance or field limitations?