Skip to Content
author's profile photo Former Member
Former Member

Transfers Delivery to ARInvoice with Freights rows

Hi,

I'm having a hard time to transfers the Freights of the delivery to the ARInvoice from the DI API

I did try all kind of things from that code :

                    //---------------------------------------------------------------------------------------------------------------------------
                    // Seems to work WITH and WITHOUT FREIGHT but I'm not sure of the procedure to do it and on SDN forum there's no explaination
                    // and the documentation is silent about it :(
                    //---------------------------------------------------------------------------------------------------------------------------
                    if (DeliveryDocument.Expenses.ExpenseCode != 0)
                    {
                        ARInvoiceDocument.Expenses.ExpenseCode = DeliveryDocument.Expenses.ExpenseCode;
                        ARInvoiceDocument.Expenses.LineTotal = DeliveryDocument.Expenses.LineTotal;
                        ARInvoiceDocument.Expenses.TaxCode = DeliveryDocument.Expenses.TaxCode;
                    }

to that code :

                        //// Trying to add the Freights rows but getting No matching record found...
                        //if (DeliveryDocument.Lines.Expenses.Count > 0)
                        //{
                        //    for (int iFreight = 0; iFreight < DeliveryDocument.Lines.Expenses.Count; iFreight++)
                        //    {
                        //        DeliveryDocument.Lines.Expenses.SetCurrentLine(iFreight);

                        //        ARInvoiceDocument.Lines.Expenses.ExpenseCode = DeliveryDocument.Lines.Expenses.ExpenseCode;
                        //        ARInvoiceDocument.Lines.Expenses.LineTotal = DeliveryDocument.Lines.Expenses.LineTotal;
                        //        ARInvoiceDocument.Lines.Expenses.TaxCode = DeliveryDocument.Lines.Expenses.TaxCode;

                        //        if (iFreight < DeliveryDocument.Lines.Expenses.Count - 1)
                        //            ARInvoiceDocument.Lines.Expenses.Add();
                        //    }
                        //}

this commented code gives the error : No matching records found

All this to say that I really don't know how to transfers the Expenses from Delivery to AR INvoice

when there are multiple Freight rows

For everything else it works perfectly. I mean, BaseLine, BaseEntry etc..

if I do not play with Freight, the transfers occur perfectly.

Even the first piece of code above works for just 1 Freight

but as soon as there are more then one line in Freights, it is a mystery !

Not that I didn't check in the Documentation, which is very silent about it and on the forum here, well nothing clear about to do it.

Thank you for any help.

Meanwhile, I'm still trying all kind of things.

Add a comment
10|10000 characters needed characters exceeded

Related questions

9 Answers

  • Posted on Jan 29, 2008 at 04:15 PM

    Hi Marc,

    iam a bit confused about the 2nd code snipped.

    you want to add a new ARInvoiceDocument - ok.

    i dont see ARInvoiceDocument.Lines.Expenses.SetCurrentLine

    ok - you add a new row but you never set the correct line, the new lines

    dont have a expensecode because you overwrite always the first line

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 04:31 PM

    Oh Really ?

    I really have to SetCurrentLine even if its a .Add() ?

    if I do so I presume I have to do SetCurrentLine(ARInvoice.Lines.Expenses.Count) ?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 04:41 PM

    Seems that even if I do a SetCurrentLine a still have the problem. I tought that .Add() place the SetCurrentLine on it automaticly.

    here's the actual context in which I'm trying that :

                        //----------------------------------------------------------------------------------------------------------------------
                        // Now lets link the lines from the base document that means, the Invoice lines will be those from the Delivery document
                        // This is the way SAP works when time comes to transfers a Delivery to AR Invoice.
                        //----------------------------------------------------------------------------------------------------------------------
                        for (int iLine = 0; iLine < DeliveryDocument.Lines.Count; iLine++)
                        {
                            DeliveryDocument.Lines.SetCurrentLine(iLine);
    
                            ARInvoiceDocument.Lines.BaseType = (int)BoAPARDocumentTypes.bodt_DeliveryNote;
                            ARInvoiceDocument.Lines.BaseEntry = DeliveryDocument.DocEntry;
                            ARInvoiceDocument.Lines.BaseLine = DeliveryDocument.Lines.LineNum;
    
                            //// Trying to add the Freights rows but getting No matching record found...
                            if (DeliveryDocument.Lines.Expenses.Count > 0)
                            {
                                for (int iFreight = 0; iFreight < DeliveryDocument.Lines.Expenses.Count; iFreight++)
                                {
                                    DeliveryDocument.Lines.Expenses.SetCurrentLine(iFreight);
    
                                    ARInvoiceDocument.Lines.Expenses.ExpenseCode = DeliveryDocument.Lines.Expenses.ExpenseCode;
                                    ARInvoiceDocument.Lines.Expenses.LineTotal = DeliveryDocument.Lines.Expenses.LineTotal;
                                    ARInvoiceDocument.Lines.Expenses.TaxCode = DeliveryDocument.Lines.Expenses.TaxCode;
    
                                    if (iFreight < DeliveryDocument.Lines.Expenses.Count - 1)
                                    {
                                        ARInvoiceDocument.Lines.Expenses.Add();
                                        ARInvoiceDocument.Lines.Expenses.SetCurrentLine(ARInvoiceDocument.Lines.Expenses.Count);
                                    }
                                }
                            }
    
                            TotalBeforeDiscount += DeliveryDocument.Lines.Price;    // Calculating the Total before discount...
    
                            for (int iUDF = 0; iUDF < DeliveryDocument.Lines.UserFields.Fields.Count; iUDF++)
                                ARInvoiceDocument.Lines.UserFields.Fields.Item(DeliveryDocument.Lines.UserFields.Fields.Item(iUDF).Name).Value = DeliveryDocument.Lines.UserFields.Fields.Item(iUDF).Value;
    
                            if (iLine < DeliveryDocument.Lines.Count - 1)
                                ARInvoiceDocument.Lines.Add();
                        }
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 04:45 PM

    I also have this piece of code on the HEADER level which I don't even know if this is necessary. But what I know is that if I do not use the Lines level

    this piece works as for ONE Freight row

                        //---------------------------------------------------------------------------------------------------------------------------
                        // Seems to work WITH and WITHOUT FREIGHT but I'm not sure of the procedure to do it and on SDN forum there's no explaination
                        // and the documentation is silent about it :(
                        //---------------------------------------------------------------------------------------------------------------------------
                        if (DeliveryDocument.Expenses.ExpenseCode != 0)
                        {
                            ARInvoiceDocument.Expenses.ExpenseCode = DeliveryDocument.Expenses.ExpenseCode;
                            ARInvoiceDocument.Expenses.LineTotal = DeliveryDocument.Expenses.LineTotal;
                            ARInvoiceDocument.Expenses.TaxCode = DeliveryDocument.Expenses.TaxCode;
                        }
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 05:20 PM

    Same trouble 😔

    The SetCurrentLine is probably not the problem since I never used it and I always had all the lines of the delivery before using the Freights

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Marc,

      don't give up.

      1. try once to reduce the lines count... you are starting with zero !

      for (int iLine = 0; iLine < DeliveryDocument.Lines.Count - 1; iLine++)

      if this fails

      2. try to add once only two lines per code, and use setcurrentline. it might worked in past but

      i recommend you to use it.

      regards

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 05:58 PM

    Hi 😊

    Ok

    #1 gives me 5002 Internal Error

    #2 I don't understand this one 😊

    Add a comment
    10|10000 characters needed characters exceeded

    • i meant that you should act tactical.

      (i have many addons with freight and it always works.)

      add a single document line with TWO freight.

      use a document where the line has two freight costs 😊

      iLine = 0

      DeliveryDocument.Lines.SetCurrentLine(iLine);

      ARInvoiceDocument.Lines.SetCurrentLine(iLine);

      ARInvoiceDocument.Lines.BaseType = (int)BoAPARDocumentTypes.bodt_DeliveryNote;

      ARInvoiceDocument.Lines.BaseEntry = DeliveryDocument.DocEntry;

      ARInvoiceDocument.Lines.BaseLine = DeliveryDocument.Lines.LineNum;

      iFreight = 0;

      DeliveryDocument.Lines.Expenses.SetCurrentLine(iFreight);

      ARInvoiceDocument.Lines.Expenses.SetCurrentLine(iFreight);

      ARInvoiceDocument.Lines.Expenses.ExpenseCode = DeliveryDocument.Lines.Expenses.ExpenseCode;

      ARInvoiceDocument.Lines.Expenses.LineTotal = DeliveryDocument.Lines.Expenses.LineTotal;

      ARInvoiceDocument.Lines.Expenses.TaxCode = DeliveryDocument.Lines.Expenses.TaxCode;

      iFreight++;

      DeliveryDocument.Lines.Expenses.SetCurrentLine(iFreight);

      ARInvoiceDocument.Lines.Expenses.Add();

      ARInvoiceDocument.Lines.Expenses.SetCurrentLine(iFreight);

      ARInvoiceDocument.Lines.Expenses.ExpenseCode = DeliveryDocument.Lines.Expenses.ExpenseCode;

      ARInvoiceDocument.Lines.Expenses.LineTotal = DeliveryDocument.Lines.Expenses.LineTotal;

      ARInvoiceDocument.Lines.Expenses.TaxCode = DeliveryDocument.Lines.Expenses.TaxCode;

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 06:28 PM

    Sorry

    The Expenses are at the HEADER level not at the Lines level

    I did try this :

                        if (DeliveryDocument.Expenses.ExpenseCode != 0)
                        {
                            //ARInvoiceDocument.Expenses.ExpenseCode = DeliveryDocument.Expenses.ExpenseCode;
                            //ARInvoiceDocument.Expenses.LineTotal = DeliveryDocument.Expenses.LineTotal;
                            //ARInvoiceDocument.Expenses.TaxCode = DeliveryDocument.Expenses.TaxCode;
                            ARInvoiceDocument.Expenses.BaseDocEntry = DeliveryDocument.DocEntry;
                            ARInvoiceDocument.Expenses.BaseDocType = (int)BoAPARDocumentTypes.bodt_DeliveryNote;
                            ARInvoiceDocument.Expenses.BaseDocLine = DeliveryDocument.DocNum;
                        }
    

    And this gives No matching records found.

    and I have 2 Freights. One at 5.00 and one at -5.00

    Lets try to make it work for the Header freight. And yet, I've been unsuccessful at transfering the Freights from the Delivery to the ARInvoice.

    God this is hard. The documentation is so poor at everything we can do with the DI API !

    Add a comment
    10|10000 characters needed characters exceeded

    • ok, iam getting confused. (let's try a dirty code)

      you told - this works:

      DeliveryDocument.Expenses.SetCurrentLine(0);

      ARInvoiceDocument.Expenses.ExpenseCode = DeliveryDocument.Expenses.ExpenseCode;

      ARInvoiceDocument.Expenses.LineTotal = DeliveryDocument.Expenses.LineTotal;

      ARInvoiceDocument.Expenses.TaxCode = DeliveryDocument.Expenses.TaxCode;

      than just add

      DeliveryDocument.Expenses.SetCurrentLine(1);

      ARInvoiceDocument.Expenses.Add();

      ARInvoiceDocument.Expenses.SetCurrentLine(ARInvoiceDocument.Expenses.Count -1);

      ARInvoiceDocument.Expenses.ExpenseCode = DeliveryDocument.Expenses.ExpenseCode;

      ARInvoiceDocument.Expenses.LineTotal = DeliveryDocument.Expenses.LineTotal;

      ARInvoiceDocument.Expenses.TaxCode = DeliveryDocument.Expenses.TaxCode;

      don't link it, just try this.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 07:31 PM

    Ok after HOURS of Trying and Errors here's the working solution :

                        //----------------------------------------
                        // Additional expenses at the HEADER level
                        //----------------------------------------
                        if (DeliveryDocument.Expenses.Count > 0)
                        {
                            for (int iFreight = 0; iFreight < DeliveryDocument.Expenses.Count; iFreight++)
                            {
                                DeliveryDocument.Expenses.SetCurrentLine(iFreight);
    
                                if (DeliveryDocument.Expenses.ExpenseCode != 0)
                                {
                                    ARInvoiceDocument.Expenses.BaseDocEntry = DeliveryDocument.DocEntry;
                                    ARInvoiceDocument.Expenses.BaseDocType = (int)BoAPARDocumentTypes.bodt_DeliveryNote;
                                    ARInvoiceDocument.Expenses.BaseDocLine = DeliveryDocument.Expenses.LineNum;
                                    ARInvoiceDocument.Expenses.LineTotal = DeliveryDocument.Expenses.LineTotal;
    
                                    if (iFreight < DeliveryDocument.Expenses.Count - 1)
                                        ARInvoiceDocument.Expenses.Add();
                                }
                            }
                        }
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 29, 2008 at 07:31 PM

    Found the solution. Check the message above

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.