Hi,

In this post will present the code where SysDa framework can be used to implement Exist method.

Note: CG_SysDaQueryExist is a runnable class.

class CG_SysDaQueryExist
{       
    /// <summary>
    /// SysDaQueryObject - Implementing Exist method.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {     
        /*
            Effective X++ Statement -
            while select SalesId, SalesStatus
                from salesTable
                    where salesTable.SalesStatus == SalesStatus::Invoiced
            {
            }
        */
 
        SalesId salesId = "002";
        boolean recordExists = CG_SysDaQueryExist::exist(salesId);
 
        if (recordExists == true)
        {
            info(strFmt("Record exists with salesorder %1", salesId));
        } 
    }
 
    static boolean exist(SalesId  _salesId)
    {
        SalesTable          salesTable;
        SysDaQueryObject    sysDaQuery = new SysDaQueryObject(SalesTable);
 
        if (!_salesId)
        {
            return false;
        }
       
        // Imposes optimistic lock
        sysDaQuery.optimisticLockHint = true;
 
        // Select firstonly
        sysDaQuery.firstOnlyHint = true;
 
        sysDaQuery.projection().add(fieldStr(SalesTable, RecId));
 
        sysDaQuery.whereClause(new SysDaEqualsExpression
                            (new SysDaFieldExpression(SalesTable, fieldStr(SalesTable, SalesId)),
                                new SysDaValueExpression(_salesId)));
           
        SysDaFindObject findObject = new SysDaFindObject(sysDaQuery);
        new SysDaFindStatement().execute(findObject);
 
        return (salesTable.RecId !=0);
    }
 
}

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

Regards,

Chaitanya