Thursday, May 16, 2024

Like operator in Dynamics 365 F&O

Using the 'Like' and 'Not Like' Operators in Dynamics 365 F&O for Efficient Data Filtering


The `like` and `not like` operators in Dynamics 365 Finance and Operations provide powerful querying capabilities for pattern matching within data fields. The `like` operator allows for the selection of records that match a specified pattern, as demonstrated in the `LSSelectClaimRecordsWithIn` class, which retrieves claim records starting with "in". Conversely, the `not like` operator enables the exclusion of records matching a pattern, as shown in the `SelectClaimRecordsNotStartingWithIn` class, which selects claim records that do not start with "In". These operators are instrumental in filtering and retrieving relevant data from large datasets efficiently. Proper utilization of these operators can significantly enhance data querying and reporting capabilities within the ERP system.


Like operator :

class LSSelectClaimRecordsWithIn extends RunBase
{
    public static void main(Args _args)
    {
        SelectClaimRecordsWith obj = new SelectClaimRecordsWith();
        obj.run();
    }

    public void run()
    {
        ClaimTable claimTable;
        select * from claimTable
            where claimTable.ClaimNumber like 'in%';

        while (select * from claimTable
            where claimTable.ClaimNumber like 'in%')
        {
            info(strFmt("ClaimNumber: %1, ClaimDate: %2, ClaimAmount: %3", 
                        claimTable.ClaimNumber, 
                        claimTable.ClaimDate, 
                        claimTable.ClaimAmount));
        }
    }
}



Not Like operator :

class SelectClaimRecordsNotStartingWithIn extends RunBase
{
    public static void main(Args _args)
    {
        SelectClaimRecordsNotStartingWithIn obj = new SelectClaimRecordsNotStartingWithIn();
        obj.run();
    }

    public void run()
    {
        ClaimTable claimTable;
        select * from claimTable
            where !(claimTable.ClaimNumber like 'In%');

        while (select * from claimTable
            where !(claimTable.ClaimNumber like 'In%'))
        {
            info(strFmt("ClaimNumber: %1, ClaimDate: %2, ClaimAmount: %3", 
                        claimTable.ClaimNumber, 
                        claimTable.ClaimDate, 
                        claimTable.ClaimAmount));
        }
    }
}