9
votes

Is there something similar to the famous toString() method of C# in Axapta?

I try to run underlying code:

info(this.dataSource());

But it gives me this error message: "Argument 'txt' is incompatible with the required type."

4
info expects a string value. There is no automatic conversion. - Jan B. Kjeldsen

4 Answers

9
votes

The toString is available on all objects but usually not of much value:

info(this.dataSource().toString())

This gives this output:

Class FormDataSource Address

Probably you knew that already! However the query datasource does give something useful:

FormDataSource fds = this.dataSource();
;
info(fds.query().dataSourceTable(tableNum(Address)).toString());

gives the corresponding SQL query:

SELECT FIRSTFAST * FROM Address
2
votes

If you are only looking for the name of the dataSource you can do the following:

info(this.dataSource().name());
1
votes

Unfortunately not, but there are a number of "...2Str()" methods for converting base data types to string, for example;

int2Str() http://technet.microsoft.com/en-us/library/aa851371(v=ax.50).aspx

int642str() http://technet.microsoft.com/en-us/library/aa851371(v=ax.50).aspx

date2str() http://msdn.microsoft.com/en-us/library/aa857241(v=ax.10).aspx

Plus others.

1
votes

I just want to add that I often use strFmt.

Counter c = 25;
int id = 3;
;
info(strfmt("Record number %1, id = %2", c, a)); //Record number 25, id = 3 

It is similar to String.Format() in C#. You can see more details here.