Data manipulation commands in Dynamics 365 for Finance and Operations


internal final class POLDataManipulationCommands
{
    /// 
    /// Class entry point. The system will call this method when a designated menu 
    /// is selected or when execution starts and this class is set as the startup class.
    /// 
    /// The specified arguments.
    public static void main(Args _args)
    {
        POLDataManipulationCommands obj = new POLDataManipulationCommands();
        obj.whileSelectExample();
    }


    public void whileSelectExample()
    {
        POLMobileServiceTable polMobileServiceTable;

        while select * from polMobileServiceTable
            where polMobileServiceTable.ModelID == 'Apple'
        {
            info (strfmt("%1, %2", polMobileServiceTable.IMEINumber, polMobileServiceTable.ServiceID));
        }
    }

    public void createRecord()
    {
        //insert into POLServiceTable (ServiceID, ModelID) values("SERV01234", "Apple")

        POLMobileServiceTable polServiceTable;

        polServiceTable.ServiceID               = "SERV_Code";
        polServiceTable.ModelID                 = "Samsung";
        polServiceTable.ExpectedServiceAmount   = 5000;
        polServiceTable.IssueDescription        = "Software udpate";
        polServiceTable.IMEINumber              = "IMEI9898";
        polServiceTable.insert(); //Insert record to database
    }

    public void updateRecord()
    {
        //Select the desired record
        POLMobileServiceTable polServiceTable = POLMobileServiceTable::find("SERV_Code", true);

        //assign the values to buffer for updation
        //update the record
        ttsbegin;
        polServiceTable.ServiceStatus = POLServiceStatus::Repaired;
        polServiceTable.update();
        ttscommit;
        
        info ("Record updated.");
    }

    public void deleteRecord()
    {
        //Select the desired record
        POLMobileServiceTable polServiceTable = POLMobileServiceTable::find("SERV_Code", true);

        //assign the values to buffer for updation
        //update the record
        ttsbegin;
        polServiceTable.delete();
        ttscommit;
        
        info ("Record deleted.");
    }

}