Unable to find the standard code for User Standard functionality allow copy purch lines from one order to another using form \Forms\PurchCopying

Hi All,
I am new to D365f&0, I am trying to find the code for standard functionality where we can copy purch lines through Purchase Orders >> Line>>Purchase order lines>>From All (in Purchase order form).

I am unable to find the standard code for this functionality like how it is copying the lines from VendInvoiceTrans to Purchline. Kindly guide me


After selecting the record from invoice headers than clicking on OK it is copying the line to selected PurchOrder in purchase order form.

Thankyou in advance.

I would start the investigation from the end - the place where a PurchLine is initialized from VendInvoiceTrans. In such a case, it’s common to implement an initFrom* method and PurchLine indeed has a method called initFromVendInvoiceTrans(). When I right-click its name and choose Find references, I find that it’s used at a few places, one of them is copyFromSource() method of PurchLineCopyFromVendInvoiceTrans class. This seems to be what you’re looking for.

An alternative to Find references is adding a breakpoint to the method, attaching debugger to the web server and running the process through the form.

If you want to know where PurchLineCopyFromVendInvoiceTrans.copyFromSource() is called from, you can use one of these techniques again.

Thankyou Martin the above information is really helpful to me.

Hi Martin,
I created InvoiceId(string) field in purchline table and placed it in the purchaseOrder form.

I intended to populate the field with InvoiceId related to copied line from VendInvoicetrans at the time of copying the line.if I am copying another line it should show the InvoiceId related to that particular line. The field displaying the InvoiceId but it is showing for selected line invoiceId not the current copied line InvoiceId.Please guide me

I extended initFromVendInvoiceTrans() method and below is the code I written



void initFromVendInvoiceTrans(VendInvoiceTrans  _vendInvoiceTrans,
                                  boolean           _copyPrecisely,
                                  boolean           _copyPriceDisc,
                                  boolean           _copyQty,
                                  Qty               _qty,
                                  PdsCWInventQty    _pdsCWQty
                                  )
     {
     
          next initFromVendInvoiceTrans(_vendInvoiceTrans,_copyPrecisely,_copyPriceDisc,_copyQty,_qty,_pdsCWQty);
          Purchline purchline;
          ttsbegin;
          select forupdate purchline 
               where purchline.PurchId == this.PurchId;
          this.PurchId = _vendInvoiceTrans.InvoiceId;
          purchline.update();
          ttscommit;
     }

Putting InvoiceId on PurchLine sounds wrong to me. It assumes that there may be only a single invoice, but you can actually may have several invoices invoicing parts of an order.

In your code, you always select the first line of the order, not necessarily the line related to the invoice line. You call update on purchLine, you never change any value.

You’re trying to change PurchId, which is a bug.

To find invoice line for a purch line, look for VendInvoiceTrans records where InventTransId is the same as on the order line.

1 Like