The not-so-rookie Rides Again - Building a global procedure

Hi all,

In my old Access-based applications, I have many form fields that allow data selection through drop down lists tied to a background table, basically just like we do with Comboboxes and valuelists. In addition, if the entry that a user wants isn’t in the list, they can double-click on the field, which opens a dialog that allows them to add to the list (and the background table).

Now, in Servoy, I’ve set up fields as comboboxes, and attached valuelists to them. In order to let the user add new items that aren’t in the valuelist, I’m trying to build a generic procedure that will…

  1. Figure out what form it is in
  2. Figure out what field it is in
  3. Figure out what value list is tied to the field
  4. Figure out what table is tied to the value list
  5. Figure out what field in the table is tied to the value list
  6. Create a foundset for the table and add the item to it.

So far…
I’ve created fields as combo boxes with valuelists tied to them. There are a variety of value lists.

I’ve set up the field as “editable” to allow them to type in a new entry.

The onDataChange fires, and I can create a foundset based on the table attached to the valuelist to make sure that the entry isn’t already in the table (it might also be possible to just interrogate the valuelist entries, but I’m not sure how to do that).

If they want to add it, I can create a new record in the foundset, put the new data into it, and save it.

So, I can do this for an individual field without any problems.

As far as creating the global/generic version of this…

I’ve found that I can use controller.getName() to determine what form I’m on.

I haven’t been able to figure out how to determine what field I’m on. I was thinking of looking to see what field has focus, but while I can find methods to set focus. I haven’t yet found a way to ask what field currently has focus. From another entry in the Forum, I have found that while the user will need to leave the field in order to have the onDataChange fire, the field doesn’t actually lose focus until the onDataChange returns. But, I’m not sure if using focus is the right way to do this.

Once I figure out the field, I should be able to use the “valuelist” property of the field to see what valuelist is being used.

Once I figure out the valuelist, I should be able to use the “tableName” property of the value list to see what table is being used.

I haven’t yet figured out how to see what field on the table is being used to fill the value list, but I’m thinking, perhaps, getDisplayDataProviderIds.

Any thoughts on this?

As always, thanks for your assistance.

Ron

Hi Ron,
I havent got my develop on hand,
but can’t you use the event param of onDataChange to get the formname (event.getFormName()) and the field (event.getElementName()).

Hi jos,

That could very well be. I’ll check into that. Thanks so much for the reply.

Ron

Hi again,

Well, thanks to that help, I’ve been able to make a good deal of progress. Ran into another stumbling block, tho. Here’s the code I’ve written so far…

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

Now this gets me most of the information that I need, but I’m having a problem getting the information into the search. The line "dcfoundset.mydataprovider[0] = newValue is generating a warning, and if failing in runtime. The warning message is…
The property mydataprovider is undefined for the type JSFoundsetdb:/workingartist/tblartworksubject

And at runtime, I’m getting his error on the same line…
TypeError: Cannot set property “0.0” of undefined to “Portrait” (C:\Users\Ron\servoy6_workspace\WorkingArtist\forms\frmartwork_new.js#914)

During runtime with the Smart Client in debug, if I look in the Interactive Console at mydataprovider[0], it has a value of “subject” in this particular test. What I want is to have dcfoundset.mydataprovider[0] to resolve to “dcfoundset.subject” for this search.

Thanks again for any thoughts you all might have.

Have a good day.

Ron

Problem one is that you have two dots in dcfoundset…mydataprovider[0]. Problem two is, there is no dataprovider called mydataprovider[0]. You can use an associative notation, however:

dcfoundset[mydataprovider[0]]

Hi Patrick,

Thanks for that information.

The two dots aren’t actually in the code that I’m testing. That was a mis-type on my part.

I agree on problem two. The idea was that I would get the dataprovider from the array which is loaded in the previous code, but that wasn’t working (obviously). I’ll give your suggestion a try. Thanks very much.

Have a good day/evening.

Ron

I understood the idea and it was good. It just has to be scripted slightly different.

Hi,

Okay, so it seems that I’ve got some sort of notation problem here.

I tried the suggestion above by implementing the code as

dcfoundset[mydataprovider[0]] = newValue

For this test, newValue is equal to “portrait”.

Looking in the debugger’s interactive console…
The value of mydataprovider[0] is “subject”, which is what it should be (this is the field in the table underlying the value list)
After executing the code line above, the value if dcfoundset[mydataprovider[0]] is undefined.
The search does run, but returns a value of 6, which is the number of entries in the entire table, and not 1, which is the number of records that contain “portrait” in the subject field.

I’m sorry, but I’m not familiar with the correct use of this notation, so I may be making a simple mistake.

If I were to hardcode this line of code for one specific example, it would read…
dcfoundset.subject = 'portrait"
newValue does have “portrait” in it, but so far I’m unable to get the left side of the assignment statement to resolve correctly. The idea is to have the dataprovider represented in the assignment statement by something that is filled dynamically depending on the valuelist being used.

I suspect that I’m still not constructing the statement properly, so any suggestions would be appreciated.

Thanks again.

Ron

HI all,

As I wrote in my other post, I finally found the problem this morning, in the line that fills the array with the dataproviders. A few more tweaks, and I’ll have myself a nice new global procedure.

Thanks again for all of your input.

Ron