How to get the fields and their field records count in info log in x++

Hi Team,

Please help me on the X++ code for a table how many fields are in a table and along with count of how many records in a particular fields related records total

for example one field having no records( zero records), one field having some of the lines empty records

I want to display the if field having zero records that particular fields i need the select statement

in the infolog.

You’ve attached version tags for both AX 2009 and AX 2012. Does it mean that you need a solution that will work in both versions (and therefore it can’t be based on the modelstore database, which doesn’t exist in AX 2009)?

Also, fields don’t have records, therefore your requirement doesn’t make a good sense to me. Do you mean how many records have a value in the given field?

Hello Martin,

Thanks for your reply.

Requirement is ax 2009, But actually we are migrating ax 2009 to D365 in that we want to know how many fields having null records and how many fields having records exists.

its manually it will take time for comparing the data how many fields having with out records exists

I am finding x++ code for fields having zero records that means all the lines with that particular field it will be empty.

Thanks

naidu

The number of fields is relatively easy - you’ll get it from SysDictTable.fieldCnt(). But think more about your requirements - in particular, do you want to include system fields or not?

Regarding the calculation of non-empty values, I would try something like this:

int countNonEmpty(TableId _tableId, FieldId _fieldId)
{
	Query q = new Query();
	QueryBuildDataSource ds = q.addDataSource(_tableId);
	ds.addRange(_fieldId).value(SysQuery::valueNotEmptyString());
	
	SysQuery::countTotal(new QueryRun(q));
}

But it may need more effort to work with any data type.