General X++ Development

How do I use `select firstOnly` in X++?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I use select firstOnly in X++?

SSunny Vasty75 reputation · answered Aug 13, 2026

Use firstOnly when you only need one matching record.

X++
CustTable custTable;

select firstOnly custTable
    where custTable.AccountNum == 'US-001';

if (custTable.RecId)
{
    info(custTable.name());
}

If you only need one row, say that in the query. There is no reason to loop through a result set just to stop after the first record.