Is x = forms.formname[relname,fieldname] supported syntax?

Hi,

I’m trying to write a flexible substitution system for bulk mailing,

I have a form, let’s call it ‘mailinglist’. I use controller.setSelectedIndex() in a loop to move down the list.

to get the value relating to a specific record, I use

var relationshipname = arguments[0];
var fieldname = arguments[1];
var v = forms.mailinglist[relationshipname,fieldname];

assuming this will pick the value for the current record.

It doesn’t!!!
It always picks up the value of the first record.

Is this syntax supported, so this is a Servoy bug…
or
am I streching javascript too far and need to rewrite?

Instead of setting the selected index, you should use getRecord. So change your code to something like

for (var i = 1; i <= foundset.getSize(); i++) {
   var vRecord = foundset.getRecord(i);
   // now call your method and pass the record
   myMethod(vRecord, 'relationshipName', 'fieldName');
}

in “myMethod” you do

var vRecord = arguments[0];
var relationshipname = arguments[1];
var fieldname = arguments[2];
var v = vRecord[relationshipname][fieldname];

Using getRecord() is a lot faster than setting the selectedIndex and is more robust in general.

just tried:

var x = controller.getDataProviderValue(relationshipname + '.' + fieldname);

Same error I get the first record in the list, although I can see

controller.getSelectedIndex()

increasing…

Servoy 3.1.3_01
Mac OS X
Java 1.5

Thank you Patrick, your technique works fine! And is of course faster :wink: