Hi experts, here I go again... hahaha...
Well... I have a problem that I think it can be a Patch Level issue, but also cannot be... Let the facts...
I'm trying to insert a draft document of type "oReturns", with one item, a Sales Tree, that have two childs inside it. But, when I do oDraft.Add(), DI API returns the following error message: [-5002] Warehouse is not assigned to the same branch as the document [DRF1.WhsCode][line: 2] , '1'
I reviewed all the points where I know I have to select branches, such as the warehouse and business partner's master data, and both are marked to work with the desired branch.
The error messages refers a line number 2, but, analyzing the generated XML before adding the document, it has only one line, the line number 0.
Below is the code snippet where I insert the document as well as the generated XML before inserting it.
For information, I'm working in SAP Business One 8.82 PL 11.
Here's the code snippet
Documents oDraftNote = (Documents)oCompany.GetBusinessObject(BoObjectTypes.oDrafts);oDraftNote.DocObjectCode = BoObjectTypes.oReturns;oDraftNote.CardCode = "C002521";oDraftNote.BPL_IDAssignedToInvoice = 5;oDraftNote.DocDate = DateTime.Now;oDraftNote.DocDueDate = DateTime.Now;oDraftNote.TaxDate = DateTime.Now;oDraftNote.SequenceCode = -2;oDraftNote.SequenceSerial = 45;oDraftNote.Lines.ItemCode = "KWI00002";oDraftNote.Lines.Quantity = 20.00;oDraftNote.Lines.Price = 1.000000;oDraftNote.Lines.Usage = "18";oDraftNote.Lines.TaxCode = "5905.001";oDraftNote.Lines.WarehouseCode = "999";oDraftNote.Lines.Add();if (oDraftNote.Add() != 0){ int errCode; string errorMsg; oCompany.GetLastError(out errCode, out errorMsg); errMsg = string.Format("[{0}] {1}", errCode, errorMsg); throw new Exception(errMsg);}
And here's the XML
<?xml version="1.0" encoding="UTF-16"?><BOM> <BO> <AdmInfo> <Object>112</Object> <Version>2</Version> </AdmInfo> <Documents> <row> <DocType>dDocument_Items</DocType> <Printed>psNo</Printed> <DocDate>20130510</DocDate> <DocDueDate>20130510</DocDueDate> <CardCode>C002521</CardCode> <Confirmed>tYES</Confirmed> <TaxDate>20130510</TaxDate> <PartialSupply>tYES</PartialSupply> <DocObjectCode>16</DocObjectCode> <RevisionPo>tNO</RevisionPo> <BlockDunning>tNO</BlockDunning> <Pick>tNO</Pick> <PaymentBlock>tNO</PaymentBlock> <MaximumCashDiscount>tNO</MaximumCashDiscount> <Rounding>tNO</Rounding> <DocumentSubType>bod_None</DocumentSubType> <UseShpdGoodsAct>tNO</UseShpdGoodsAct> <BPL_IDAssignedToInvoice>5</BPL_IDAssignedToInvoice> <ReserveInvoice>tNO</ReserveInvoice> <SequenceCode>-2</SequenceCode> <SequenceSerial>45</SequenceSerial> <SequenceModel>0</SequenceModel> <UseCorrectionVATGroup>tNO</UseCorrectionVATGroup> <InsuranceOperation347>tNO</InsuranceOperation347> <ArchiveNonremovableSalesQuotation>tNO</ArchiveNonremovableSalesQuotation> <CashDiscountDateOffset>0</CashDiscountDateOffset> <NTSApproved>tNO</NTSApproved> <EDocGenerationType>edocNotRelevant</EDocGenerationType> <EDocStatus>edoc_Ok</EDocStatus> <GroupHandWritten>tNO</GroupHandWritten> <CreateOnlineQuotation>tNO</CreateOnlineQuotation> <ClosingOption>coByCurrentSystemDate</ClosingOption> <OpenForLandedCosts>tYES</OpenForLandedCosts> <RelevantToGTS>tNO</RelevantToGTS> <IsAlteration>tNO</IsAlteration> </row> </Documents> <Document_Lines> <row> <LineNum>0</LineNum> <ItemCode>KWI00002</ItemCode> <Quantity>20.000000</Quantity> <Price>1.000000</Price> <WarehouseCode>999</WarehouseCode> <TreeType>iNotATree</TreeType> <UseBaseUnits>tNO</UseBaseUnits> <BaseType>-1</BaseType> <TaxCode>5905.001</TaxCode> <ShippingMethod>-1</ShippingMethod> <CorrectionInvoiceItem>ciis_ShouldBe</CorrectionInvoiceItem> <DeferredTax>tNO</DeferredTax> <Usage>18</Usage> <LineType>dlt_Regular</LineType> <WithoutInventoryMovement>tNO</WithoutInventoryMovement> </row> </Document_Lines> <Document_LinesAdditionalExpenses> <row> <LineNumber>0</LineNumber> <GroupCode>0</GroupCode> <TaxLiable>tYES</TaxLiable> <TaxType>aext_NormalTax</TaxType> <BaseGroup>-1</BaseGroup> </row> </Document_LinesAdditionalExpenses> <Document_SpecialLines> <row></row> </Document_SpecialLines> </BO></BOM>
Thanks in advance.
Eduardo Gonçalves