Getting a dataprovider type

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()

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

You should do something like this:

	var _table = databaseManager.getTable(currentcontroller.getServerName(),"tablename");
	var _column = _table.getColumn("columnname");
	var _type = _column.getTypeAsString();

Same reply as Joas using your code:

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]])
		}
	}
}

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:
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!