Accessing a Lotusscript variable from formula language

I'm working with Lotus notes (7) designer to create a form on which one of the fields is to be a dialog list. I would like to populate the list using 'use formula for choices' and then from the formula access a lotus script variable declared in the globals of the form. Does anyone know if this is possible? Or maybe I should be populating the list from Lotus Script?

To give a bit an example two lists defined in Lotus Script
fruits -> apple, pear, banana
vegetables -> carrot, courgette

The dialog list should show all the items of the two lists, then depending on the item chosen, if it is a fruit then one action will be taken, if it is a vegetable then another.

Thanks for any help
Who is Participating?
Sjef BosmanConnect With a Mentor Groupware ConsultantCommented:
The usual way to do this:
- create a CfD field on the form, say Choices, with formula Choices
- in the QueryOpen of the form, you write some code to create a field Choices in the document (back-end, not the UI!)
- you add the values you need to the Choices-field
- your selection list can have the formula Choices

If you want to update the chocies depending in some value on the form, you have to add some code:
- in the dialog list field, select "Refresh choices on document refresh"
- in the QueryRecalc, recompute the values for the Choices field
In other words, formula can't access LotusScript variables, so the script has to transfer the data to somethinhg that's commonly acceesible between the two languages -- a field, an environment varaible, a profile value.
ScoteqAuthor Commented:
That for that, it sounds like it is what I need, but just having a bit of trouble with the part
- write some code to create a field Choices in the document (back-end, not the UI!)
I can't see in the documentation how to do that!
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

I would use either a profile document containing the field lists or a set of documents in a view that can be accessed in  formula via @DBlookup or @DBcolumn.

All are backend.

I hope this helps !
In QueryOpen:
Source.Document.Choices = YOUR_ARRAY
Per Bill's comment... make sure your field CHOICES is of type text, COMPUTED FOR DISPLAY, allow multiple values, and prefereably with New Line being the only input/output multivalue separator. You should NOT have any documemnt with a choices value saved to it.
Sjef posted the solution (1st post), I was just clarifying.   :)
ScoteqAuthor Commented:
I have tried this example in the QueryOpen of the form

Dimm arr(1 To 10) As String

But when I open the form from a notes session I get 'Object variable' not set. Sysaffected is the name of the field as I see it in the objects tab "Sysaffected (Field)" - I get the feeling I'm missing something basic, as far as I can see, a field on the form is the same as a field backend, but are you saying this isn't the case?

Joep8020Connect With a Mentor Commented:
with a new document the backend document (Source.Document) is not available in the QueryOpen, put the code in the PostOpen and you'll be fine.

Also use a base 0 for arrays, so:
Dimm arr(0 To 9) As String

Hope this helps you.
ScoteqAuthor Commented:
Yes,  that helps thanks, I'm now seeing the contents of my array in the dialog list, but all on one line and not as separate items that can be selected.
See if there is  an option to show one item per line in the  Dialog properties.

ScoteqAuthor Commented:
Can't find a 'one line per item' property.
I've tried another way that I now think  is what sjef_bosman suggested, by creating a new item (an item is a field???)

      Dim item As New NotesItem(doc, "CHOICES","")
      Call item.AppendToTextList("This is option 1")
      Call item.AppendToTextList("This is option 2")      

I then refer to CHOICES as the formula on the UI. This works fine for a new entry, but when I go back into the form the options are no longer correct it shows the options as above, plus the option previously selected in the following format (i.e. the selected option is repeated, and split on multiple lines.
This is option 1
This is option 2
go back to the previous solution and click Allow multiple values for the Sysaffected field. An item indeed is a field.

It needs to allow multiple values to store an array (otherwise the array gets converted to single string separated with ;)
Sjef BosmanGroupware ConsultantCommented:
Allow multiple values, AND disallow most of the separators (I'd suggest just to keep the newline).

You also may run into trouble the first time after opening a new form, for everything is in the PostOpen now: the options in a dialog list are loaded during the open, so BEFORE the PostOpen is executed. Hence your options list may be empty.

Suggested way to handle this:
- put options calculation in the QueryRecalc
- trigger a refresh in the PostOpen and in the QueryModeChange (but only the form is set into edit mode!)

If you don't have this problem, so much the better, but I'm pretty sure you will have it.


PS Sorry, was away for a while... You're making good progress!

PS2 And an item is NOT a field, although most time we just assume thery are equal. I'd define an item as the on-disk representation of the contents of one name-value pair; a NotesItem is a LotusScript object that allows you to handle an item; a field is some space in a form that can hold the value of a NotesItem.
So there can be items in a document for which there is no field on a form, or fields in a form for which there is no item. Even the relationship between a document and a form is quite loose: there is the item "Form" that can hold the name of the form that is used to show the contents of a document, but that can easily be overruled if need be.

PS3 Confused? Just watch the next episode of... Soap! :-)
I was just rethinking the above and thought that none of this will work if the variable was changed when the document is open. The choices wil then not be refreshed.

All this depends ofcourse on what you are trying to achieve, but I think the best way to go is to take the opposite route.

Use a field as the base, instead of the global script variable. In your script, if you want to access the variable, just look in the field. All manipulations should be done on the field. This way you have on place to store the variable instead of two.

If the variable is document specific, and the document should record the state of the variable, the field should be computed, if the variable doesn't change use computed for display.
ScoteqAuthor Commented:
Thanks again for all your help - I didn't think this was going to be so complicated (but I guess that's why I couldn't find the solution in the documentation). Just to clarify, in my case, only one of the options can be selected, so I don't need to allow multiple values (unless this was suggested for another reason), and therefore only one option needs to be stored in the document. The list only needs to be made available for the user to select or change this option.

As I said, following your suggestions, this now works when creating a new form. It is just when editing it that things go wrong (re my last comment), so I would say the original question has been answered. Unless anyone has anymore suggestions for this part I will close the question, and try to accpet fairly the answers that helped.

ScoteqAuthor Commented:
To conclude, it turns out that as long as I don't put any spaces in the names of the different choices (but that's another question), the following code placed in the 'PostOpen' of the form works for a new entry and for editing an existing entry. allSystems being a Variant defined in Globals (Declarations), and populated in Globals - Initialize

      Dim item As New NotesItem(doc, "DL","")
      ' Populate systems affected with the array in globals
      Dim lb As Integer
      Dim ub As Integer
      Dim counter As Integer
      lb = Lbound(allSystems,1)
      ub = Ubound(allSystems,1)
      For counter = lb To ub
            Call item.AppendToTextList(allSystems(counter))            
Sjef BosmanGroupware ConsultantCommented:
Which is functionally equivalent to
     Set item= doc.ReplaceItemValue("DL", allSystems)

Thanks for the grade!
or to  Dim item As New NotesItem(doc, "DL",allSystems)

thanks as well!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.