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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Batch class not return for all records

(0) ShareShare
ReportReport
Posted on by

Hi all,

I want to write a batch class that allows it to add a line according to the objectid to the work order that has no line for all workorders. The code I wrote only adds for a work order. How can I return all work orders?

public void run()
    {
        EntAssetWorkOrderTable workOrder ;          
        
        EntAssetObjectTable objecttable;        
        
        EntAssetWorkOrderLine workOrderLine;
        
        ;
        #OCCRetryCount
     
        try
        {
            ttsbegin;
            while select workOrder
            {
               
                select firstonly objecttable
                    where objecttable.ObjectID == workOrder.ObjectID_WM;
             
                if(objecttable)
                {
                    if(workOrderLine.RecId == 0)
                    {
              

                  
                        //workOrderLine.selectForUpdate(true);
                        workOrderLine.WorkOrder = workOrder.RecId;
                        workOrderLine.Object = objecttable.RecId;
                        workOrderLine.JobType = workOrder.JobType;
                        workOrderLine.insert();
                 
                    
                    }
               
                }
               
            }
            ttscommit;
        }

I have the same question (0)
  • ergun sahin Profile Picture
    8,826 Moderator on at

    public void run()
        {
            EntAssetWorkOrderTable workOrder ;          
            
            EntAssetObjectTable objecttable;        
            
            EntAssetWorkOrderLine workOrderLine;
            
            ;
            #OCCRetryCount
         
            try
            {
                ttsbegin;
                while select workOrder
                {
                   
                    select firstonly objecttable
                        where objecttable.ObjectID == workOrder.ObjectID_WM;
                 
                    if(objecttable)
                    {
                        //clear workOrderLine or next line will create problem for you
                        workOrderLine.clear();
                        if(workOrderLine.RecId == 0)
                        {
                            
                            
                      
                            //workOrderLine.selectForUpdate(true);
                            workOrderLine.WorkOrder = workOrder.RecId;
                            workOrderLine.Object = objecttable.RecId;
                            workOrderLine.JobType = workOrder.JobType;
                            workOrderLine.insert();
                     
                        
                        }
                   
                    }
                   
                }
                ttscommit;
            }

    You need clear workOrderLine or you can delete workOrderLine.RecId control (it's meaningless anyway)

  • Granger  Profile Picture
    on at

    But I want it to run the insert if there is no record in the line. That's why I added the if condition line. How should I change it taking this into consideration?

  • Martin Dráb Profile Picture
    238,769 Most Valuable Professional on at

    You never put any value to workOrderLine variable, therefore it'll always be empty.

    If you want to check if a record exists, you need tp make a request to database. Maybe you can use one of find*() methods on EntAssetWorkOrderLine table.

  • ergun sahin Profile Picture
    8,826 Moderator on at

    As Martin said, you are not selecting data before the control line. So it's empty.

    But after the first insertion the line table has value. In the second loop (and other loops) it never skips the control because the table  has first inserted record

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 509 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 375

#3
Adis Profile Picture

Adis 268 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans