Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

how to create a Batch job to update previous packing slips

(1) ShareShare
ReportReport
Posted on by 1,457
hi,
I have a requirement to update all the packing slips with the invoice id against them 
using a batch job how can i get it done i plz guide me on it.
thanks 
 
  • Martin Dráb Profile Picture
    Martin Dráb 230,476 Most Valuable Professional on at
    how to create a Batch job to update previous packing slips
    Well, it surely can be improved, but it's worth investing into it if you'll run it just once (to update historic data)?
     
    A simple thing to consider is whether you really need to update all packing slips, maybe several years old. As always, it all depends on business requirements.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to create a Batch job to update previous packing slips
    hi martin 
     
    you were right about custPackingSlipJour  , i have removed the exist join , i am getting invoice id for the packing slip in debugger , but i am having doubt about the code that my batch job will take much time to execute how can i make the execution quick , can you suggest me on this , do i have me make any changes in code .
     public void processoperation()
        {
            CustPackingSlipJour    custPackingSlipJour;
            CustPackingSlipTrans   custPackingSlipTrans;
            CustInvoiceTrans       custInvoiceTrans;
            InventTransOrigin      inventTransOrigin;
            InventTrans            inventTrans;
            str                    curCompany;
    
            CustInvoiceJour             custInvoiceJour ;
    
    
            while select custPackingSlipJour
                where  custPackingSlipJour.DTInvoiceId == ''
              {
                   ttsbegin;
            select firstonly inventTrans
                                    group by inventTrans.PackingSlipId,inventTrans.InvoiceId
                     exists  join  inventTransOrigin
                             where   inventTransOrigin.RecId == inventTrans.InventTransOrigin
                     exists  join  custInvoiceTrans
                             where   custInvoiceTrans.InventTransId == inventTransOrigin.InventTransId
                               &&    custInvoiceTrans.InvoiceId  == inventTrans.InvoiceId
                     exists  join  custPackingSlipTrans
                             where   custPackingSlipTrans.PackingSlipId ==  inventTrans.PackingSlipId
                               &&    custPackingSlipTrans.InventTransId ==  inventTransOrigin.InventTransId
                               &&    custPackingSlipTrans.PackingSlipId  == custPackingSlipJour.PackingSlipId;
                  
                    custPackingSlipJour.reread();
                    custPackingSlipJour.selectForUpdate(true);
                    custPackingSlipJour.InvoiceId =  inventTrans.InvoiceId;
                    custPackingSlipJour.doUpdate();
                    ttscommit;
             }
          
        }
    
     thanks ,
    regards,
    dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 230,476 Most Valuable Professional on at
    how to create a Batch job to update previous packing slips
    I'm sorry, but I don't understand the description of your problem ("but is showing join expected on exist join"). The sentence doesn't make sense to me. Also, I believe that your code will end with an error on update() and it's strange that you didn't mention such a thing. Can you explain your problem once more, please?
     
    And let me give you a hint. When debugging your code, check out if custPackingSlipJour buffer contains any data before calling an update.
     
    I see two huge bugs: your using custPackingSlipJour variable for two different things and you overwrite the value inside the loop. And you don't fetch any data to custPackingSlipJour in the inner statement, exactly because you used an exist join. Please use the debugger to understand what your code does, if merely reading your code doesn't help you.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to create a Batch job to update previous packing slips
    hi martin , 
    I have updated the all the packing slips  but my execution is getting slow due to while loop .
    so i have change the code and tried to add exist join my ,but is showing join expected on exist join can you tell me where i am getting wrong.
      while select custPackingSlipJour
                where  custPackingSlipJour.DTInvoiceId == ''
              {
                   ttsbegin;
            select firstonly PackingSlipId,InvoiceId from inventTrans
                                    group by inventTrans.PackingSlipId,inventTrans.InvoiceId
                             exists  join  inventTransOrigin
                             where   inventTransOrigin.RecId == inventTrans.InventTransOrigin
                             exists  join  custInvoiceTrans
                             where   custInvoiceTrans.InventTransId == inventTransOrigin.InventTransId
                             exists  join  custPackingSlipTrans
                             where   custPackingSlipTrans.PackingSlipId ==  inventTrans.PackingSlipId
                               &&    custPackingSlipTrans.InventTransId ==  inventTransOrigin.InventTransId
                             exists  join custPackingSlipJour
                             where  custPackingSlipTrans.PackingSlipId  == custPackingSlipJour.PackingSlipId;
                  
                    custPackingSlipJour.reread();
                    custPackingSlipJour.selectForUpdate(true);
                    custPackingSlipJour.InvoiceId =  inventTrans.InvoiceId;
                    custPackingSlipJour.doUpdate();
                    ttscommit;
             }
    thanks ,
    regards ,
    dinesh 
     
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to create a Batch job to update previous packing slips
    hi martin ,
     
    i have edited the code and added find method 
    final class CustPackingSlpJrSysOperationService  extends SysOperationServiceBase
    {
        public void processoperation()
        {
            CustPackingSlipJour    custPackingSlipJour;
            CustPackingSlipTrans   custPackingSlipTrans;
            CustInvoiceTrans       custInvoiceTrans;
            InventTransOrigin      inventTransOrigin;
            InventTrans            inventTrans;
            str                    curCompany;
    
            CustInvoiceJour             custInvoiceJour ;
    
            curCompany = curExt();
    
            while select * from  custPackingSlipJour
                   join custPackingSlipTrans
                     group by custPackingSlipJour.PackingSlipId
                     where  custPackingSlipJour.PackingSlipId == custPackingSlipTrans.PackingSlipId
                   join inventTransOrigin
                     where  inventTransOrigin.InventTransId == custPackingSlipTrans.InventTransId
                     join  custInvoiceTrans
                     where custInvoiceTrans.InventTransId == inventTransOrigin.InventTransId
                   join inventTrans
                     where inventTrans.InventTransOrigin == inventTransOrigin.RecId
                      && inventTrans.InvoiceId ==  custInvoiceTrans.InvoiceId
                      && inventTrans.PackingSlipId == custPackingSlipTrans.PackingSlipId
                   join custInvoiceJour
                       where  custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId
                        &&    custPackingSlipJour.DataAreaId ==  curCompany
                        &&    custPackingSlipJour.DTInvoiceId == ''
            {
                custPackingSlipJour = custPackingSlipJour::findFromCustPackingSlipTrans(custPackingSlipTrans.SalesId,custPackingSlipTrans.PackingSlipId,custPackingSlipTrans.DeliveryDate);
                if(custPackingSlipJour.DTInvoiceId == '' )
                {
    
                    custPackingSlipJour.selectForUpdate(true);
                    custPackingSlipJour.DTInvoiceId =  custInvoiceJour.InvoiceId;
                    custPackingSlipJour.update();
                }
            }
    
           
    
        }
    
    }
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to create a Batch job to update previous packing slips
    hi ,
    martin 
    i have debugged my code , actually no record is being select for update so i am getting the error at update statement , i will post image below ,  i use find method what should i have to pass there recid?
  • Martin Dráb Profile Picture
    Martin Dráb 230,476 Most Valuable Professional on at
    how to create a Batch job to update previous packing slips
    The fact that you can't debug your code is a huge problem preventing you from doing your job, therefore resolving it is more important than writing new code that you can't debug. If you need our help, create a new thread (with an appropriate title) and explain your problem in detail there.
     
    Ask yourself why you added the group by clause there and whether the reasons are still valid. You can also explain your reasoning to us, if you want to discuss it.
     
    It's difficult for me to discuss a design of a query that doesn't make sense to me. If I really wanted something like that, I would probably use a view with a computed column returning the first invoice ID for each packing slip ID, and I would likely use this view when needed instead of writing the information to packing slips. But that's likely too advanced for you.
     
    What you can do, for example, is removing grouping and sorting the data by PackingSlipId. To prevent multiple updates of the same record, you can remember the previously processed PackingSlipId and if it's the same, you'll skip update().
     
    Or you can use grouping and then use CustPackingSlipJour::find() to load the record to update.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to create a Batch job to update previous packing slips
    hi ,
    martin ,
    i have passed the condition , i am trying to debug , but my debugger is getting exitted unexpectedly , but plz have look on my code i have made some changes you suggested ,should i remove the line from code 
     group by custPackingSlipTrans.PackingSlipId
    final class CustPackingSlpJrSysOperationService  extends SysOperationServiceBase
    {
        public void processoperation()
        {
            CustPackingSlipJour    custPackingSlipJour;
            CustPackingSlipTrans   custPackingSlipTrans;
            CustInvoiceTrans       custInvoiceTrans;
            InventTransOrigin      inventTransOrigin;
            InventTrans            inventTrans;
            str                    curCompany;
    
            CustInvoiceJour             custInvoiceJour ;
    
            curCompany = curExt();
    
            while select custPackingSlipJour
                   join custPackingSlipTrans
                     group by custPackingSlipTrans.PackingSlipId
                     where  custPackingSlipJour.PackingSlipId == custPackingSlipTrans.PackingSlipId
                   join inventTransOrigin
                     where  inventTransOrigin.InventTransId == custPackingSlipTrans.InventTransId
                     join  custInvoiceTrans
                     where custInvoiceTrans.InventTransId == inventTransOrigin.InventTransId
                   join inventTrans
                     where inventTrans.InventTransOrigin == inventTransOrigin.RecId
                      && inventTrans.InvoiceId ==  custInvoiceTrans.InvoiceId
                      && inventTrans.PackingSlipId == custPackingSlipTrans.PackingSlipId
                   join custInvoiceJour
                       where  custInvoiceJour.InvoiceId == custInvoiceTrans.InvoiceId
                        &&    custPackingSlipJour.DataAreaId ==  curCompany
                        &&    custPackingSlipJour.DTInvoiceId == ''
    
                   {
                       custPackingSlipJour.selectForUpdate(true);
                       custPackingSlipJour.DTInvoiceId =  custInvoiceJour.InvoiceId;
                       custPackingSlipJour.update();
                   }
    
           
        }
    }
     
     
    thanks ,
    regards ,
    Dinesh
  • Martin Dráb Profile Picture
    Martin Dráb 230,476 Most Valuable Professional on at
    how to create a Batch job to update previous packing slips
    To find CustPackingSlipJour records without any value in DTInvoiceId, you need to use a where clause, refer to DTInvoiceId field, use == operator and use the empty string as the value. Like this: where custPackingSlipJour.DTInvoiceId == ''.
     
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,457 on at
    how to create a Batch job to update previous packing slips
    Hi martin 
     thanks for clarifying all the things where i am getting wrong .
     can  you plz tell me how can i make the query without invoice id do i need to remove any join from my code plz let me know .
     
    thanks 
     

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans