Skip to Content
0

Item number is missing; specify an item number [INV1.ItemCode][line: 1] -5002

Nov 03, 2016 at 12:35 PM

965

avatar image
Former Member

I get the following return when I am trying to add an A/R invoice to SAP Business One via SBO Java Connector and DI API:

Cannot add A/R Invoice: Item number is missing; specify an item number  [INV1.ItemCode][line: 1] -5002

Here's part of my code:

public void addARInvoice()
{
    try
    {
        invoice = SBOCOMUtil.newDocuments(company, SBOCOMConstants.BoObjectTypes_Document_oInvoices);


        invoice.setCardCode("CA0001");
        invoice.setCardName("ACompany");
        invoice.setDocType(0);
        invoice.setDocCurrency("RMB");
        invoice.setSalesPersonCode(11);
        invoice.setJournalMemo("CA0001");
        invoice.setSeries(0);
        invoice.setPaymentGroupCode(-1);
        invoice.setDocTotal(386.86);


        invoice.setDocDate(Date.valueOf("2016-11-03"));
        invoice.setDocDueDate(Date.valueOf("2016-11-03"));
        
        invoice.getLines().add();
        invoice.getLines().setItemCode("51Z0100TB02"); 
        invoice.getLines().setVatGroup("X1"); 
        invoice.getLines().setItemDescription("BType");
        invoice.getLines().setQuantity(new Double(1));
        invoice.getLines().setPrice(new Double(386.85897));
        invoice.getLines().setTaxCode("X1"); 
        invoice.getLines().setWarehouseCode("01");
        invoice.getLines().setDiscountPercent(0.00);
        invoice.getLines().setGrossBuyPrice(new Double(452.62500));
        invoice.getLines().setLineTotal(new Double(386.86));
        invoice.getLines().setCostingCode2("810");
        invoice.getLines().setCOGSCostingCode("1190");
        invoice.getLines().setCOGSCostingCode2("810");
        invoice.getLines().setPriceAfterVAT(386.86);
        invoice.getLines().setCurrency("RMB");

        if (invoice.add() == 0) 
        {
            System.out.println("Successfully added A/R Invoice");
        }
        else 
        {
            // get error message fom SAP Business One Server
            SBOErrorMessage errMsg = company.getLastError();
            System.out.println(
                    "Cannot add A/R Invoice: "
                    + errMsg.getErrorMessage()
                    + " "
                    + errMsg.getErrorCode()
            );
        }


    }
    catch(SBOCOMException e)
    {
        System.out.println("err");
        e.printStackTrace();
    }
    
}<br>

My SBO client version is 9.1 with DI API installed. Could you help me?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
avatar image
Former Member Nov 03, 2016 at 01:10 PM
2

Hi Hao,

I normally use the C# version but, you are calling invoice.getLines().add(); which adds a row to the invoice.

The normal SDK behavior is that a line is already available to you when you create an "invoice" object.

Meaning that calling add will make it two rows.

You can check if the behavior is the same in Java by removing the invoice.getLines().add();

Good luck.

Pedro Magueija

LinkedIn | Twitter | Blog

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks!

I removed the first invoice.getLines().add() and it works.

0