Skip to main content

Notifications

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 191

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?

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: Creating a simple runnableClass which uses a parameter, but receiving a SQL error when running select

    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.

  • Superbunny Profile Picture
    Superbunny 191 on at
    RE: Creating a simple runnableClass which uses a parameter, but receiving a SQL error when running select

    Thanks for the tips!

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: Creating a simple runnableClass which uses a parameter, but receiving a SQL error when running select

    First of all, please try to synchronize the database.

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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans