Create a new Datasource and link it through code

Have you ever wanted, through code, to add a new datasource to an already existing one? Well below is some code that will show you how:

Source : here.


Make an OR in a query

Simple select query in Ax Client:

static void projTableJob(Args _args)
    ProjTable   projTable;
    while Select projTable where projTable.ProjId Like "305492-00*" ||
                                 projTable.Name   Like "305492-00*"
        print projTable.Name;

Using Query Classes in Ax Client: The same query is implemented by using Query classes in Ax client

static void projTableJobUsingQuery(Args _args)
    Query                   query;
    QueryBuildDataSource    qb, qb1;
    QueryBuildRange         qbr, qbr1;
    QueryRun                qr;
    ProjTable               projTable;
    str                     myvalue = '305492-00*';
    query = new Query();
    qb = query.addDataSource(tablenum(ProjTable), "ProjTable");
    qbr = qb.addRange(fieldnum(ProjTable, ProjId));
// Here the OR condition is implemented.   
    qbr.value(strfmt('(%1.%2 Like "%3") || (%1.%4 Like "%5")',
                fieldstr(ProjTable, ProjId), any2str(myvalue),
                fieldstr(ProjTable, Name),  any2str(myvalue)
    qr = new QueryRun(query);
    while (
        projTable = qr.get(tablenum(ProjTable));
        print projtable.Name;