9

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."

Jonathan Bravetti
  • 2,187
  • 2
  • 11
  • 28
Tassisto
  • 8,589
  • 27
  • 91
  • 140

4 Answers4

9

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
Jan B. Kjeldsen
  • 17,339
  • 5
  • 30
  • 49
  • 1
    .toString() is useful on AX collection classes as well, such as the Array type. Array.toString() will often output readable contents. If you have an array of classes or something odd, perhaps not. – Alex Kwitny Mar 07 '12 at 17:29
  • 1
    I always try to avoid using datSourceNo() in production code because the dataSourceNo can change. If you modify the form or report and add or remove (or even change the order of) dataSources, this will break your code. I have seen this occur in base Microsoft code when upgrading from 4.0 to 2009, they changed the order of some datasources and it broke lookups that were using the DataSourceNo. I always try to use dataSource().Name(), becuase that is much less likely to change. – Michael Brown Mar 08 '12 at 13:38
2

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

info(this.dataSource().name());
Michael Brown
  • 2,231
  • 1
  • 17
  • 34
1

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.

alexlz
  • 548
  • 1
  • 7
  • 22
1

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.

AnthonyBlake
  • 2,314
  • 1
  • 22
  • 38
  • @IllDevelopIt I will update answer - are you trying to get the datasource description or the contents to a string!?! – AnthonyBlake Mar 07 '12 at 13:37