cancel
Showing results for 
Search instead for 
Did you mean: 

How can I do a partial delivery with DI programmatically?

Former Member
0 Kudos

Hi at all,

I want to do a partial delivery programmatically, but the base document order gets closed!

This is what I do:

I create an order with Business One and allowed partial delivery. With SDK I create a delivery note based on this order.<BR> Next I manipulate the quantity oDelivery.Lines.Quantity = 1 (itu2019s less than in the base document). <BR>I add the new document. That works fine, but my based document is closed.

What do I wrong?

Thanks for your help!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi, thank you for your answers.

For programming with DI I use the java connector (JCO).

The partial delivery flag is set in the based order document.

This is my code snippet, which looks up a docentry and a customer cardcode via SQL. <br>

With these information I want to add a partial delivery note based on the referenced order document with several positions<br> (ordered quantity ist greater than 2 pieces)


public void createODLN(int ordernumber) {
  try {
    IDocuments delivery;
    IDocuments order;
    IDocument_Lines pos;
    IRecordset rs = null;
    String sql;
    int docentry;

    delivery = SBOCOMUtil.newDocuments(sboCompany, SBOCOMConstants.BoObjectTypes_Document_oDeliveryNotes);
    
    // ordernumber is the DocNum in ORDR
    // but we need the DocEntry
    // 1. get the DocEntry for DocNum
    
    rs = SBOCOMUtil.newRecordset(sboCompany);
    sql = "SELECT DocEntry FROM ORDR WHERE DocNum = " + ordernumber;
    rs .doQuery(sql);

    // we have a 1:1 relation between DocNum and DocEntry
    rs.moveFirst();
    if (!rs.isEoF().booleanValue()) {
      // get the docentry
      docentry = rs.getFields().item("DocEntry").getValueInteger();
      // fill the order object
      order = SBOCOMUtil.getDocuments(sboCompany, SBOCOMConstants.BoObjectTypes_Document_oOrders, docentry);
      if (order.getByKey(docentry) == true) {
	// exists
        pos = order.getLines();
        int rowcount = pos.getCount();
        for (int i=0; i<rowcount; i++) {
	  pos.setCurrentLine(i);
          delivery.setCardCode(order.getCardCode());
          delivery.getLines().setBaseEntry(new Integer(docentry)); // Referenz aus Auftrag
          delivery.getLines().setBaseType(SBOCOMConstants.BoObjectTypes_Document_oOrders);
          delivery.getLines().setBaseLine(new Integer (pos.getLineNum()));
	  // for all positions: delivered 2 pcs.          
          delivery.getLines().setQuantity(new Double(2));
	  // add the line
          delivery.getLines().add();
        }
	delivery.add();
      }
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }

}

AdKerremans
Active Contributor
0 Kudos

Hi,

Is see one error in your code.

The Lines.Add() should be added before filling the fields and only if it is not the first line you're adding.

Regards

Ad

Answers (4)

Answers (4)

Former Member
0 Kudos

Thank you very much,

I don't really know why, but it works.

Best regards Lars

Former Member
0 Kudos

Hi Lars,

I used the following code to add a partial Delivery for order 179 which had one row with a quantity of 2:

Dim oDoc As SAPbobsCOM.Documents
        oDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oDeliveryNotes)

        oDoc.CardCode = "C1000"

        oDoc.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders
        oDoc.Lines.BaseEntry = 179
        oDoc.Lines.BaseLine = 0
        oDoc.Lines.Quantity = 1

        oReturn = oDoc.Add()

        If oReturn <> 0 Then
            oCompany.GetLastError(oError, errMsg)
            MsgBox(errMsg)
        Else
            MsgBox("Partial Delivery Added")
        End If

My Base document is still open after doing this - I tested this on 2005 A and 2007 A on a Demo database.

Hope this is useful, let me know if you still have any issues.

Regards

Niall

SAP Business One Forums Team

Nussi
Active Contributor
0 Kudos

Hi Lars,

Willkommen im Forum

vielleicht hast Du vergessen "Teillieferung" im Auftrag anzuklicken.

Unter Logistik gibt es ja eine CheckBox dafür ...

nur so eine Idee

EDIT:

probier die Eigenschaft PartialSupply auch in Deinem oDelivery Object

lg David

Edited by: David Nussböck on Sep 4, 2008 12:14 PM

AdKerremans
Active Contributor
0 Kudos

Hi Lars,

do you set the quantity before or after the basefields?

It should set after the basefields.

Can you post your piece of code?

Regards

Ad