[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1258
  • Last Modified:

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
0
Scoteq
Asked:
Scoteq
  • 6
  • 4
  • 3
  • +3
2 Solutions
 
Sjef BosmanGroupware 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
0
 
qwaleteeCommented:
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.
0
 
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!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
SysExpertCommented:
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 !
0
 
Bill-HansonCommented:
In QueryOpen:
Source.Document.Choices = YOUR_ARRAY
0
 
qwaleteeCommented:
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.
0
 
Bill-HansonCommented:
Sjef posted the solution (1st post), I was just clarifying.   :)
0
 
ScoteqAuthor Commented:
I have tried this example in the QueryOpen of the form

Dimm arr(1 To 10) As String
arr(1)="aaa"
arr(2)="bbb"
Source.Document.Sysaffected=arr

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?

Thanks
0
 
Joep8020Commented:
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
arr(0)="aaa"
arr(1)="bbb"

Hope this helps you.
0
 
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.
0
 
SysExpertCommented:
See if there is  an option to show one item per line in the  Dialog properties.

0
 
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
This
is
option
2
--------------------------
0
 
Joep8020Commented:
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 ;)
0
 
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.

Sjef

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! :-)
0
 
Joep8020Commented:
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.
0
 
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.



 
0
 
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))            
      Next
0
 
Sjef BosmanGroupware ConsultantCommented:
Which is functionally equivalent to
     Set item= doc.ReplaceItemValue("DL", allSystems)

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

thanks as well!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now