Getting a dataprovider type

Questions, tips and tricks and techniques for scripting in Servoy

Getting a dataprovider type

Postby dpearce » Wed May 06, 2009 5:09 pm

Is there anyway to return the dataprovider type?

I am trying to create an automatic replacement of fields from a letter template, but i get stuck when the field is a date.

If there is a way of checking to see if the dataprovider is a date and then doing a conversion to text, it would be very neat.
I thought i had cracked it when i found the .getTypeAsString() function, but maybe i am using it wrongly.

you cannot say dataprovider.getTypeAsString()
Code: Select all
var fields=forms.LETTER_TEMPLATE.alldataproviders
for ( var i = 0 ; i < fields.length  ; i++ )
{

if (utils.stringPatternCount(globals.letter_edit, '<<'+fields[i]+'>>')>0){

--> Want to check the type of field that fields[i] is here so i can change it to text if it is a date<--
globals.letter_edit=globals.letter_edit.replace('<<'+fields[i]+'>>', forms.LETTER_TEMPLATE[fields[i]])

}


}


Thanks for telling me where i am being stupid!

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Getting a dataprovider type

Postby Joas » Wed May 06, 2009 5:53 pm

You should do something like this:
Code: Select all
   var _table = databaseManager.getTable(currentcontroller.getServerName(),"tablename");
   var _column = _table.getColumn("columnname");
   var _type = _column.getTypeAsString();
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: Getting a dataprovider type

Postby david » Fri May 08, 2009 7:44 am

Same reply as Joas using your code:

Code: Select all
var fields = forms.LETTER_TEMPLATE.alldataproviders
var table = forms.LETTER_TEMPLATE.controller.getServerName(), forms.LETTER_TEMPLATE.controller.getTableName())
for ( var i = 0 ; i < fields.length  ; i++ ) {
   if (utils.stringPatternCount(globals.letter_edit, '<<'+fields[i]+'>>')>0) {
      if (table.getColumn(fields[i]).getTypeAsString() == "DATETIME") {
         // format the date before replacing
      }
      else {
         globals.letter_edit = globals.letter_edit.replace('<<'+fields[i]+'>>', forms.LETTER_TEMPLATE[fields[i]])
      }
   }
}
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Getting a dataprovider type

Postby dpearce » Fri May 08, 2009 8:37 am

Thanks,

thats really helpful. I knew it could be done. Its unbelievable to be able to do a search and replace from a letter template using no more than about 10 lines of code.

Last time i did this in Filemaker, i had to specify a line for each field to search and replace!

This will sort out the dates nicely so they dont come back as ''

Thanks

David
dpearce
 
Posts: 469
Joined: Sun Dec 03, 2006 11:53 am

Re: Getting a dataprovider type

Postby david » Fri May 08, 2009 8:46 am

dpearce wrote:Last time i did this in Filemaker, i had to specify a line for each field to search and replace!


And wasn't that using some sort of nested text function (substitute?) buried in a calculation? Been 6+ years ago now for me but I do remember that formatting the crazy calculation so that I didn't leave off a closing parenthesis was my biggest issue!
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.


Return to Methods

Who is online

Users browsing this forum: No registered users and 34 guests

cron