web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

X++ query bug with order by

(0) ShareShare
ReportReport
Posted on by 5
An unpleasant discovery with some inherited code today.
 
This block of code does not order results as expected because the field used does not exist, it does however compile without issue.
str lineDisc = 'Disc.';
date curDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());

PriceDiscAdmTable priceDiscAdmTable;
PriceDiscAdmTrans priceDiscAdmTrans;

while
	select priceDiscAdmTable
		order by priceDiscAdmTable.ModifiedDateTime desc // ***THIS FIELD DOES NOT EXIST***
		where (PriceDiscAdmTable.Posted == 1)
	join priceDiscAdmTrans
		where (priceDiscAdmTrans.JournalNum == priceDiscAdmTable.JournalNum) && (priceDiscAdmTrans.ItemRelation == lineDisc) && (PriceDiscAdmTrans.FromDate <= curDate) && (PriceDiscAdmTrans.ToDate >= curDate)
{
	discounts.addEnd(priceDiscAdmTrans);
}
 
the intended code
 
str lineDisc = 'Disc.';
date curDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());

PriceDiscAdmTable priceDiscAdmTable;
PriceDiscAdmTrans priceDiscAdmTrans;

while
	select priceDiscAdmTable
		where (PriceDiscAdmTable.Posted == 1)
	join priceDiscAdmTrans
		order by priceDiscAdmTrans.ModifiedDateTime desc // ***THIS FIELD DOES EXIST***
		where (priceDiscAdmTrans.JournalNum == priceDiscAdmTable.JournalNum) && (priceDiscAdmTrans.ItemRelation == lineDisc) && (PriceDiscAdmTrans.FromDate <= curDate) && (PriceDiscAdmTrans.ToDate >= curDate)
{
	discounts.addEnd(priceDiscAdmTrans);
}
 
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 405 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 322 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans