The Not-so-rookie Rides Again - Getting proper syntax

Hi all,

This is an extension of my previous post about building global procedures and dynamically filling in data. Right now, I’ve got most of it working, but I’m having a problem getting the final piece to fit. Here’s a summary…

I have many places in my system where the user can provide data into fields through way of comboboxes. If the data they want isn’t in the valuelist attached to the combobox, they can type it into the field, and the system will sense that the data is not in the table underlying the valuelist and ask if the user wants to add it. I can code this for every field doing this, but I want to create a global procedure and fill in the necessary data dynamically.

Right now, if the user types in new data, when they hit enter or tab out of the field, an onDataChange event is triggered. Within that code, I can determine what form I’m in, what field I’m in, the valuelist attached to the field, and table behind the valuelist, and the field in the table that’s the data provider for the valuelist. I can see valid data in all of these fields from within the debugger.

Basically, I do a search to see if newValue is in the table, and if not, I can add it. As a hard coded example, this works fine for constructing a search field…

dcfoundset.subject = newValue

dcfoundset is a foundset that I create using the table underlying the valuelist. “subject” needs to be replaced with a variable that can be filled in with the value of the field from the table, dynamically. I know what field it is from
mydataprovider = solutionModel.getValueList(myvlist).getReturnDataProviderIds()

mydataprovider should be an array filled with the dataproviders for this value list (for these tables there is only one dataprovider for the valuelist). What I haven’t been able to figure out is how to use that to specify the dataprovider for the search.

I’ve tried dcfoundset.mydataprovider[0] = newValue and
dcfoundset[mydataprovider[0]] = newValue

Both generate warnings and runtime errors.

So, I’m kind of unclear at this point what I’m doing wrong. I suspect it’s probably just a syntax issue, but there could be another problem I’m not seeing.

Here’s the rest of the code…

var myform = event.getFormName()
var myfield = event.getElementName()
var myvlist = solutionModel.getForm(myform).getField(myfield).valuelist.name
var myvlisttable = solutionModel.getValueList(myvlist).tableName
var mydataprovider = new Array()
mydataprovider = [solutionModel.getValueList(myvlist).getReturnDataProviderIds()]

/** @type {JSFoundsetdb:/workingartist/tblartworksubject} */
var dcfoundset = databaseManager.getFoundSet(‘workingartist’,myvlisttable)
if (dcfoundset.find()) {
dcfoundset[mydataprovider[0]] = newValue
var result = dcfoundset.search()
if (result == 0) {
var dlgresult = globals.DIALOGS.showWarningDialog(‘WorkingArtist Message’,‘This is not in the list. Would you like to add it?’,‘yes’,‘no’)
blah blah blah

Any thoughts you might have would be appreciated.

Thanks and have a good day.

Ron

Just FYI,

After playing around with this for awhile, I finally abandoned trying to get this to work, and just wrote my own SQL statement rather than relying on the search function. I’d still like any thought you might have on why I couldn’t get it to work with search, but I’ve got it working fine with a SQL statement.

Thanks again.

ron

Hi all,

This morning, with a fresh set of eyes, I went back and too another look at this code, and found the error, which was in the line where the array gets filled with the dataproviders. Too many brackets. Took those off, and the world was a happy place. With a few more little tweaks, the code will work like a charm.

Nice way to start a day.

Ron

Hi Ron,
I suspect I am trying to do something very similar could I ask a question?
I’m trying to use a TYPE_AHEAD rather than a combobox and I’m also saving the lookup tables ID into my table rather than the values being displayed (these are descriptions) however I don’t seem able to capture the information the user is typing into the field?
Could you point me in the right direction?
Many thanks
Caroline

Hi Caroline,

I guess I’m not sure exactly what you’re asking (although someone else may look at this and understand immediately; such is the nature of my “not-so-rookieness” at this point :-)).

Are you saying that in your field, set up for type-ahead, you’re allowing them to type in a new value and that data isn’t being captured?
And that in your valuelist, you’re displaying the value for the field, but actually storing the key to a record in another table that actually holds the value? (That would be pretty common).

I can tell you what I know about this from my own example, which may or may not apply to you. The field that your user is typing into has to have it’s “editable” property set to true. In my code, what I’m doing is having the “on data change” event fire whenever the user does something in that field. If the data they typed in matches a value in the lookup table that underlies the valuelist, then everything is fine and I proceed. If, however, the value does not exist in the lookup table, I put up a dialog asking if they want to add it, and if they respond yes, then I execute some code that does that. I know that this works for combo-boxes because I’m using it quite a bit now. Whether that applies to type-ahead fields the same way, I’m not entirely sure.

Does that help?

Have a good day.

Ron

Many thanks for the reply Ron and Yes I am doing exactly as you described.
Luckily João pointed out how to capture the typed text so that part is now sorted.
I’ve just got to sort the whole adding a record to a related table and I’ll be there :? (that’s giving a few headaches at the moment!)
Many thanks
Caroline