LotusScript - Why do we use array index to access value of text field - lotus-notes

I am working on some LotusScript code and came across this syntax to access a text field value: textField(0). I checked this field's properties in the design and it has the type of Text and doesn't allow multiple values. But why do we use the index to access this field value? I need to describe what the code is doing so it makes a difference between "get the value of textField then do something" vs. "get the first element of textField then do something".

The LotusScript expression document.textField is a shorthand form of document.GetItemValue("textField"). As explained in Designer Help, this expression always returns an array of strings for text or text list fields. That's why one has to use document.textField(0), or document.GetItemValue("textField")(0) for that matter, to access the first (and possibly only) element in the returned array.

An important thing to remember is that just because the field properties say that multiple values aren't allowed today, they might have been allowed in the past. Nothing gets "fixed up" in old documents if you change the properties in Domino Designer. Your code always has to consider that possibility.
And for that matter, even when the field properties do say that multiple values aren't allowed, those properties only apply when a user is editing the document using the defined form. An agent or code using any of the Notes APIs can always store multiple values in any text field.
That's why you always access item values through an array. It's not just a matter of "that's how the API works". It's a matter of how the underlying storage works.
And remember: Notes is schemaless. You have to always assume the following:
The item that corresponds to the field might not exist.
The item might be empty even if there's a validation formula that requires it to be filled in.
The item that corresponds to a text field might not actually be a text item.
The item can contain a list even if the multi-values property is not checked.

Related

populating multiple fields with same label via DocuSign API

We have several templates that take advantage of using same named labels to populate the data entered in one field to others with the same label throughout envelope documents.
According to API method Envelopes::EnvelopeRecipientTabs, in order to make this work via the API, I needed to add \\* (two back slashes) prior to the label name so that data pushed to a field would populate all and not just the first occurrence of a field with that label.
example: "tabLabel": "\\*Contract_Number"
This seemed to do the trick.
However, now I'm finding this works like a wild card. I have another field labeled "existing_contract_number" and the data for \\*contract_number populates this field.
I know I can change the name of the field so that the ending doesn't match, but there are many fields and many templates I will need to sift through to see if this is an issue elsewhere AND to fix this particular occurrence.
Is there something I am missing? Can I get the data to populate in all fields that exactly match the tabLabel without using essentially a wildcard?
Thank you.
I suggest listing the template's tabs or the envelope's tabs using a method such as EnvelopeRecipientTabs::list -- Note its include_anchor_tab_locations query parameter if you're using anchor tabs.
Once you have the entire list of tabs, update the values of just the desired tabs.
This may be more work than changing the template but will probably be a more generalized solution for your app.

Kentico - Change Pagetype Field Name without blanking out current values

I have a custom page type for Staff and there's a field called Function. I have a WHERE condition in a repeater like this: Function LIKE '%insurance%' and got an error Incorrect syntax near the keyword 'Function'
From the error I guess Function is a reserved keyword, so I changed the field name to BusinessFunction. However right after changing the field name, I noticed all the values for that field become blank. If I changed it back, the values are back to normal. The question: is there a way to change the field name while keeping the values that are already there -- without access to the backend database?
Wrap the word Function in brackets like so should resolve the problem: [Function]
When you say the values of the field are blank do you mean on the display side in the repeater? Have you changed the transformation to use the new field name? Have you updated the Columns property of the repeater to use the new field name vs. the old one? It will not lose all the data, you just need to ensure all the values of the property/field name are updated everywhere including any custom code you might be using for this page type.

OR query in eWAM - picker

So in a picker in eWam / wynsure the field usually gets passed directly to some sort of OQL statement.
Hence, if I want to search for a field whose value ends in "asdf", I enter "%asdf" into the picker field.
My question is thus: from the picker, is there anyway to specify 'I want all entries that end in "asdf" OR "qwer"'?
If not, I would recommend that this become a feature as it would be very useful to be able to enter all that right in the text field.
There is currently no way to search multiple strings in a single field beyond using wildcards. One can do this easily by creating multiple fields in the picker.
Alternatively one could customize the picker as follows:
use a presearch string (that the user fills out),
parse that string for some element (like a pipe),
Break the string up and put each part in to off screen search variables.
You are still using multiple fields, but the user get's a different experience. Keep in mind the dangers of parsing out the user input, using something like or would work out very badly splitting up words, & could show up in a company name...

Lotus Notes: What will be the view selection formula to select a form which is in different database?

My view is one application and a required form along with few fields are in different application.
Point one: A View's selection formula does not "select a form". It selects documents. These documents are (usually) created with a Form, and they (usually) contain an item called "Form" which contains the name of the Form that they were created with. So a selection formula SELECT Form = "Foo" means that the view will show all documents with an item named Form that contains the value "Foo".
Point two: A View can only select documents that are in the same database that contains the View. It cannot select documents that exist in another database.
Ergo, there is no possible forumla that selects documents in another database that were created with a given Form.
I'm assuming you probably have some keyword documents in a different database, and you'd like to use a key in the main document to pull some matching information from the keyword database. In other words, you'd like to do a "join" in your Notes view.
You can't do this, never mind whether the documents are in the same database. This is not a relational database.
There are options, however.
You could create a "user definable" column and automatically update the column formula in a profile document so that the formula can calculate the keyword correspondences. You would have a periodic agent look at the keyword database and construct an updated formula such as, #Select("a"; "b"; "c";...; ChoiceNo) to convert the number field ChoiceNo to the value "a" (for 1), "b" (for 2), etc. If you can write a formula to display the correct values for the current keywords, this is workable provided the list never gets too long.
Domino servers are capable of accessing a DB2 relational database to construct a view index, using a feature called DB2NSF. So you can actually do a join -- but your NSF data has to be stored in DB2 as its back-end, rather than beinf stored in the NSF, for this to work. This is probably going to be more work than it's worth to you for this application.
If it is an XPages application, you can create your own data set however you like for feeding to a repeat control.

How to Compute a Field in a Form from another Form or View in a Lotus DB

I have form "A" which there is a field that I need be computed after composed from Form "B". The forms are in the same database. I am not sure if it would be better to have the Form "A" field compute after composed from a "View" that uses the Form "B" or what would be the best way to get the field populated.
I have tried to do a #DBlookup, with no success.
Thank you!
Forms do not contain information, only documents do. Forms just represent information stored in documents.
Assume you have a view with name: "viewName" and it displays a set of documents.
The first sorted column of this view contains key values.
We want to get value of field someField by key from this view.
Create a new form, create a "Computed when composed" field and set the following formula as value:
#DbLookup("":"NoCache"; #DbName; "viewName"; "keyValue"; "someField");
It will access view "viewName" in the current database, get a document by "keyValue" and return value of field with name "someField"
I have tried to do a #DBlookup, with no success.
Well, what went wrong? Why didn't this work? When do you a #DbLookup call, you need to provide a view, a "key" and the field or view column you want to pull back from the matching document. Assuming you have a key with which you can link document A and document B, the look-up should be pretty straightforward.

Resources