Skip to Content
avatar image
Former Member

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

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Nov 03, 2016 at 01:10 PM

    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

    Add comment
    10|10000 characters needed characters exceeded