I'd like to fetch the table.tablename object dynamically in a serverside JavaScript so I can reuse a script in multiple forms with different tablenames.
Something like the "event.getOwner().elementName".
Example:
I use a form with a dropdown that runs a script at onChange. The script fetches the value of the dropdown and does some magic stuff. The dropdown is part of a table so I use table.tablename.dropdown.value to get the value. I'd like to get it as following (for example):
otable = event.getTable();
otable.dropdown.value;
Is that possible?
JavaScript get table.tablename object
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 8
- Joined: Wed Aug 14, 2013 9:18 am
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
-
- Ebase User
- Posts: 118
- Joined: Tue Oct 23, 2012 7:01 am
- Location: The Netherlands
-
- Ebase User
- Posts: 8
- Joined: Wed Aug 14, 2013 9:18 am
Thanks Harry for pointing us in the right direction. You're code doesn't fulfill our needs completely because "event.owner.elementName" will give us the fieldcontrol instead of the tablename. Therefore we need to add the tablename to the fieldcontrol and split the name so we get the tablename. The code below works but I still hope that the same thing is possible without adding the tablename to the fieldcontrol like this: "FIELDCONTROL1@@TABLE_NAME".
Code: Select all
var owner = event.owner.elementName;
var tableName = owner.substring(owner.indexOf('@@'));
var myTable = tables.getTable(tableName);
var neededValue = myTable.DROPDOWN.value;
Last edited by vin@haarlem on Wed Nov 20, 2013 9:16 am, edited 1 time in total.
0 x
-
- Ebase User
- Posts: 8
- Joined: Wed Aug 14, 2013 9:18 am
SOLVED
Problem solved! This is the right and fully dynamic code:
Code: Select all
var field = event.owner.getField();
var fieldName = field.elementName;
var tableName = fieldName.substring(0, fieldName.indexOf('-'));
var myTable = tables.getTable(tableName);
var neededValue = myTable.DROPDOWN.value;
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
You should also be able to get the table name from the table column:
Code: Select all
var field = event.owner.getField();
var tableName = field.table.elementName;
0 x
Who is online
Users browsing this forum: No registered users and 6 guests