1

I created a query like this:

enter image description here

now, i want to call this query inside my runBaseBatch class:

class Exercise_RunbaseBatch extends RunBaseBatch
{

    private void customerLookup(FormStringControl _control)
    {
        SysTableLookup sysTableLookUp;
        QueryBuildDataSource qbds;
        Query query = new Query();

        qbds = query.addDataSource(tableNum(CustTable));

        sysTableLookUp = SysTableLookup::newParameters(tableNum(CustTable), _control, true);

        sysTableLookUp.addLookupfield(fieldNum(CustTable, AccountNum));

        sysTableLookUp.parmQuery(query);
        sysTableLookUp.performFormLookup();
    }

    public Object dialog()
    {

        DialogRunbase dialog = super();
        DialogRunBase dialogLookUP = super();
        FormBuildStringControl control;

        DialogField dialogField = new DialogField(dialog);
        DialogField dialogFieldLookUp = new DialogField(dialog);

        dialogFieldLookUp = dialog.addField(extendedTypeStr(AccountNum));
        control = dialogFieldLookUp.control();

        dialogField = dialog.addField(extendedTypeStr(LogisticsAddressCountryRegionId));
        control.registerOverrideMethod(methodStr(FormStringControl, lookUp),methodstr(Exercise_RunbaseBatch, customerLookup),this);

         return dialog;
    }

    public boolean runsImpersonated()

    {

        return true;

    }

    public boolean showQueryValues()

    {

        return true;

    }

    public static   Exercise_RunbaseBatch construct()

    {

        return new Exercise_RunbaseBatch();

    }

    public boolean canGoBatch()

    {

        return true;

    }

    public static void main(Args args)

    {

       Exercise_RunbaseBatch runBaseDemo = Exercise_RunbaseBatch::construct();

        runBaseDemo.getLast();

        if(runBaseDemo.prompt())

        runBaseDemo.run();

    }

    public void run()

    {

        super();

    }

}

How i can do it?

OiRc
  • 1,602
  • 4
  • 21
  • 60
  • 1
    Your question is not about this, but please consider using the SysOperation framework instead of the RunBaseBatch framework. See [https://learn.microsoft.com/en-us/dynamicsax-2012/developer/sysoperation-framework-overview](https://learn.microsoft.com/en-us/dynamicsax-2012/developer/sysoperation-framework-overview) for further information (it is written for [tag:dynamics-ax-2012], but also applies to [tag:dynamics-365-operations]). – FH-Inway Jan 28 '20 at 18:25

1 Answers1

3

To use/call an AOT query in x++, simply use the constructor of the QueryRun class.

public void run()
{
    QueryRun queryRun = new QueryRun(queryStr(AssetBalances));

    while (queryRun.next())
    {
        AssetGroup assetGroup = queryRun.get(tableNum(AssetGroup));

        //table(s) assetGroup and others as a single record result set
    }
}

As far as how to use it in your derived RunBaseBatch class, that will depend on your specific requirement and needs more information to answer.

rjv
  • 1,058
  • 11
  • 29
  • 2
    As `showQueryValues` is provided it is usual to declare the variable in `ClassDeclaration` then initialize in `initParmDefault` method. Also you will need to add the `queryrun` method and make `pack` and `unpack` do their jobs. There are loads of standard classes doing this, just do a search, so no need to reiterate here. – Jan B. Kjeldsen Jan 28 '20 at 15:51