Using default format for DB field

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Using default format for DB field

Postby steve1376656734 » Mon Aug 21, 2017 10:02 am

I have set a default format for a field in the .dbi file. This works perfectly when using the field as a data provider on a form but I now need to insert the field into a string using the display format from the .dbi file. How can I achieve this?

I have tried the .toString() method on the field but this just converts the raw value to a string and I cant see any other property or method on the field that would be relevant.

Thanks
Steve
Steve
SAN Developer
steve1376656734
 
Posts: 178
Joined: Fri Aug 16, 2013 2:38 pm
Location: Lanzarote

Re: Using default format for DB field

Postby jasantana » Mon Aug 21, 2017 2:56 pm

Hi Steve, maybe this function helps you:

Code: Select all
/**
* @param {String} _serverName
* @param {String} _tableName
*
* @properties={typeid:24,uuid:"DA9E8A4C-F7FA-4C74-8CF2-481CC09178FE"}
*
* @return {Object}
*/
function getTableColumnProperties(_serverName, _tableName){
   /** @type {Object} */
   var _columnProperties={};
   
   /** @type {JSTable} */
   var _jsTable=databaseManager.getTable(databaseManager.getDataSource(_serverName,_tableName));
   var _columnNames=_jsTable.getColumnNames();
   
   _columnNames.forEach(function(_item){
      /** @type {JSColumn} */
      var _jsColumn=_jsTable.getColumn(_item);
      _columnProperties[_item].dataProviderID=_jsColumn.getDataProviderID();
      _columnProperties[_item].defaultFormat=_jsColumn.getDefaultFormat();
      _columnProperties[_item].description=_jsColumn.getDescription();
      _columnProperties[_item].foreignType=_jsColumn.getForeignType();
      _columnProperties[_item].length=_jsColumn.getLength();
      _columnProperties[_item].title=_jsColumn.getTitle();
      _columnProperties[_item].type=_jsColumn.getType();
      _columnProperties[_item].typeAsString=_jsColumn.getTypeAsString();
   });
   
   return _columnProperties
}


Though you might want to change and/or return some other properties.

Cheers,
Best regards,
Juan Antonio Santana Medina
[email protected]
EAGER BEAVER 2011
EAGER BEAVER 2012
Servoy 6.x - Servoy 7.x - Servoy 8.x - MySQL - PostgreSQL - Visual Foxpro 9
User avatar
jasantana
 
Posts: 540
Joined: Tue Aug 10, 2010 11:40 am
Location: Leeds - West Yorkshire - United Kingdom

Re: Using default format for DB field

Postby steve1376656734 » Mon Aug 21, 2017 3:17 pm

Hi Juan,

Thanks for the suggestion. I had thought about using the table properties but had hoped there was a simpler way of doing it. I think I might file a feature request for this to get the field in either display or edit format.

Thanks
Steve
Steve
SAN Developer
steve1376656734
 
Posts: 178
Joined: Fri Aug 16, 2013 2:38 pm
Location: Lanzarote

Re: Using default format for DB field

Postby steve1376656734 » Mon Aug 21, 2017 3:27 pm

Feature request filed: SVY-11475
Steve
SAN Developer
steve1376656734
 
Posts: 178
Joined: Fri Aug 16, 2013 2:38 pm
Location: Lanzarote


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 3 guests