Mar 4, 2015

How to use "OR" in X++ Query ..

static void projTableJobUsingQuery(Args _args)
{
    Query                   query;
    QueryBuildDataSource    qb, qb1;
    QueryBuildRange         qbr, qbr1;
    QueryRun                qr;
    SalesTable              salesTableLocal;
str salesid1, salesid2;
    str                     custAccountVal = "0000000015";
str                     invoiceAccountVal = "0000000025";
    ;
salesid1 = "ECM-20000091";
salesid2 = "ECM-20000094";
    query = new Query();
    qb = query.addDataSource(tablenum(Salestable));
qb.addRange(fieldnum(Salestable, SalesId)).value(queryRange(salesId1,SalesId2));
    qbr = qb.addRange(fieldnum(Salestable, CustAccount));

// Here the OR condition is implemented.  
    qbr.value(strfmt('((%1.%2 == "%4") || (%1.%3 == "%5"))',
                qb.name(),
                fieldstr(Salestable, CustAccount),
                fieldstr(Salestable, InvoiceAccount),custAccountVal,invoiceAccountVal));

    qr = new QueryRun(query);
    while (qr.next())
    {
        salesTableLocal = qr.get(tablenum(SalesTable));
        info(salesTableLocal.SalesId);
    }

  
}

No comments: