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

Community site session details

Session Id :

Using SysDa Framework to implement X++ query relational operations in D365FO.

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post, I will present the code where we can implement different relational operations like equals to, not equals to, greater than etc. used in X++ queries using SysDa framework.

Note: CG_SysDaQueryRelationOps is a runnable class.

class CG_SysDaQueryRelationsOps
{       
    /// <summary>
    /// SysDaQueryObject - Using SysDaEqualsExpression and SysDaNotEqualsExpression
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
        /*
            Effective X++ Statement -
            while select RecId, SalesId, SalesQty, SalesType
                from salesLine
                    where ((salesLine.SalesId == "0002")
                        && (salesLine.SalesType != SalesType::Sales)
                        && (salesLine.SalesQty > 0))
            {
            }
        */
 
        SalesLine           salesLine;
        SysDaQueryObject    sysDaQuery = new SysDaQueryObject(salesLine);
 
        sysDaQuery.projection().add(fieldStr(SalesLine, SalesId));
        sysDaQuery.projection().add(fieldStr(SalesLine, ItemId));
        sysDaQuery.projection().add(fieldStr(SalesLine, SalesQty));
        sysDaQuery.projection().add(fieldStr(SalesLine, SalesType));
        sysDaQuery.projection().add(fieldStr(SalesLine, RecId));
 
        sysDaQuery.whereClause(new SysDaEqualsExpression
                                (new SysDaFieldExpression(salesLine, fieldStr(SalesLine, SalesId)),
                                 new SysDaValueExpression("0002"))
                          .and(new SysDaNotEqualsExpression
                                (new SysDaFieldExpression(salesLine, fieldStr(SalesLine, SalesType)),
                                 new SysDaValueExpression(SalesType::Sales)))
                          .and(new SysDaGreaterThanExpression
                                (new SysDaFieldExpression(salesLine, fieldStr(SalesLine, SalesQty)),
                                 new SysDaValueExpression(0)))
                              );
 
        SysDaSearchObject    searchObject = new SysDaSearchObject(sysDaQuery);
        SysDaSearchStatement searchStmt = new SysDaSearchStatement();
 
        while (searchStmt.nextRecord(searchObject))
        {
            info(strFmt("SalesId: %1, ItemId: %2, Quantity: %3", salesLine.SalesId, salesLine.ItemId, SalesLine.SalesQty));
        }
       
    }
 
}

Output: https://drive.google.com/open?id=1HlVTgpOqV6OV_quJMO1Kg3jyJZJKsLZ3

Regards,

Chaitanya Golla

Comments

*This post is locked for comments