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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Creating a simple runnableClass which uses a parameter, but receiving a SQL error when running select

(0) ShareShare
ReportReport
Posted on by 329

I wish to create a reusable runnableClass which uses parameters to edit sales Orders. I started with a simple class with 1 parameter:

``

internal final class MyRunnableClass extends RunBase
{
RecId salesLineRecId1;
DialogField Dialog_salesOrderRecId;

public Object dialog()
{
Dialog dialog = super();
dialog.caption("Sales Order Update");
Dialog_salesLineRecId1 = dialog.addField(extendedTypeStr(RecId), "SalesLine 1 RecId");
return dialog;
}

public boolean getFromDialog()
{
salesLineRecId1 = Dialog_salesLineRecId1.value();
return super();
}

public static void main(Args _args)
{
MyRunnableClass script = new MyRunnableClass();
if(script.prompt())
{
script.run();
}
}

public void run()
{
SalesLine salesline;
ttsbegin;
select firstonly forupdate salesline
where salesline.recid == salesLineRecId1;
if (salesline.recid != 0)
{
salesline.CustomerRef = "Test";
salesline.doUpdate();
}
ttscommit;
}

}

``

When I run this, I receive the following error:

Microsoft.Dynamics.Ax.Xpp.ErrorException: 'Cannot select a record in Order lines (SalesLine).
The SQL database has issued an error.'

And the following stackTrace:

at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue, interpret* ip)
at Microsoft.Dynamics.Ax.MSIL.cqlCursorIL.EndFind(IntPtr table)
at Dynamics.AX.Application.MyRunnableClass.`run() in xppSource://Source/MyRunnableClass\AxClass_MyRunnableClas.xpp:line 69
at Dynamics.AX.Application.MyRunnableClass.run()
at Dynamics.AX.Application.MyRunnableClass.`main(Args _args) in xppSource://Source/MyRunnableClass\AxClass_MyRunnableClass.xpp:line 54
at Dynamics.AX.Application.MyRunnableClass.main(Args _args)
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)

Does anyone know why I encounter this error?

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    238,734 Most Valuable Professional on at

    First of all, please try to synchronize the database.

    By the way, note that there is a newer framework since AX 2012: SysOperation.

  • Superbunny Profile Picture
    329 on at

    Thanks for the tips!

    Will look into the new framework, but a simple sync DB solved it indeed!

  • Martin Dráb Profile Picture
    238,734 Most Valuable Professional on at

    When you get an error regarding database (like 'The SQL database has issued an error'), running the DB sync is always worth a try. It often solves the problem, or it'll tell you about another problem that prevents DB sync from doing its job.

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

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 577 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 309

#3
Diego Mancassola Profile Picture

Diego Mancassola 259

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans