Announcements
No record found.
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; }
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)
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?
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.
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.
Congratulations to our 2026 Super Stars!
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
André Arnaud de Cal... 509 Super User 2026 Season 1
Giorgio Bonacorsi 375
Adis 268 Super User 2026 Season 1