dataprovider type from a related table

Questions, tips and tricks and techniques for scripting in Servoy

dataprovider type from a related table

Postby paulc » Thu Jul 22, 2010 9:22 pm

I was wondering if anyone knows how to retreive a dataprovider type from a related table?

I think I can do a couple splits of the returned value and then rerun the databaseManager.getTable("kv_orders").getColumn("split_value").getTypeAsString()) but was wondering if there was an easier way to do this?

Okay so this is what I have done.

Code: Select all
var lv_dataProvider = lv_element.getDataProviderID().split('.');
      var lv_dataProvider_table = new Array();
      (lv_dataProvider.length > 1)?lv_dataProvider_table = lv_dataProvider[0].split('_to_'):lv_dataProvider_table.push(databaseManager.getTable(form.foundset).getSQLName());
     
      lv_searchFieldValues.push(new Array(lv_element.getName(),databaseManager.getTable(globals.security_current_database_server, lv_dataProvider_table[lv_dataProvider_table.length - 1]).getColumn(lv_dataProvider[lv_dataProvider.length - 1]).getTypeAsString()));


Thanks
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: dataprovider type from a related table

Postby rgansevles » Tue Aug 10, 2010 4:59 pm

Paul,

You can also get everything before the dot in the dataprovider (if there is a dot).
If you eval that you will get a related foundset that has a getDataSource() method.

Via databasemanager.getTable(fs).getColumns(stuffafterdot) you have the column.

This way you are not depending on any naming convention for relations.

Hope this helps,

Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: dataprovider type from a related table

Postby paulc » Thu Aug 12, 2010 1:09 am

Thanks for the reply Rob.

Would you be able to supply a little code for this example? I am trying the following and not able to get a foundset from the eval.

Code: Select all
var fs = eval(lv_dataProvider[0]);
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: dataprovider type from a related table

Postby rgansevles » Mon Aug 16, 2010 12:18 pm

Something like this?

Code: Select all
var dpstring = 'myrel1.myrel2.dp'   
var idx = dpstring.lastIndexOf('.')
if (idx >= 0)
{
  fs = eval(dpstring.substring(0, idx))
}


Rob
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

Re: dataprovider type from a related table

Postby Harjo » Tue Aug 17, 2010 10:23 pm

you can get into trouble using the eval() function. (BTW Servoy is always telling us NOT to use the eval() ! :wink: )
for example if you fire this code in another module, where this relation does not exist you will get an error

Most of the time you know also the scope or name of the form.
so I should do it this way:

Code: Select all
var vEvent = arguments[0] //get the event object
var vForm = vEvent.getFormName()
var vDP = 'myrel1.myrel2.dp'      
var vIdx = vDP.lastIndexOf('.')
if (vIdx >= 0) {
     var vFS = forms[vForm][vDP.substring(0, vIdx)]
}
Harjo Kompagnie
ServoyCamp
Servoy Certified Developer
Servoy Valued Professional
SAN Developer
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands


Return to Methods

Who is online

Users browsing this forum: No registered users and 5 guests

cron