cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

oInventoryGenEntry creation error

Baranyai_Csaba
Explorer
0 Likes
306

SAPbobsCOM.Recordset recordSet = (SAPbobsCOM.Recordset)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
recordSet.DoQuery($"SELECT TOP 1 DocEntry FROM OWOR WHERE Comments like '%{process.UserKey}%'");
if (!recordSet.EoF) // Ellenőrzés, hogy van-e eredmény
{

string docEntry = recordSet.Fields.Item("DocEntry").Value.ToString();

SAPbobsCOM.ProductionOrders productionOrder =
(SAPbobsCOM.ProductionOrders)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders);

int docEntryInt = int.Parse(docEntry);
bool found = productionOrder.GetByKey(docEntryInt);
Console.WriteLine($"DocEntry: {docEntryInt}, Found: {found}");
int productionOrderDocEntry = productionOrder.AbsoluteEntry;
if (process.Output == true)
{
recordSet.DoQuery($"SELECT TOP 1 DocEntry FROM OIGN WHERE Comments like '%{process.UserKey}%'");
if (recordSet.EoF)
{
SAPbobsCOM.Documents inventoryGenEntry = (SAPbobsCOM.Documents)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry);
SAPbobsCOM.Items item = (SAPbobsCOM.Items)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
if (item.GetByKey(process.Material))
{
DateTime StartDate;
if (DateTime.TryParse(process.StartTime, out StartDate))
{
inventoryGenEntry.DocDate = StartDate;
}
inventoryGenEntry.Comments = "dSuite azonosító: " + process.UserKey + "\n" + process.Remarks;
inventoryGenEntry.DocObjectCode = SAPbobsCOM.BoObjectTypes.oInventoryGenEntry;
//inventoryGenEntry.DocumentsOwner = 44;
inventoryGenEntry.Lines.BaseType = 202;
inventoryGenEntry.Lines.BaseEntry = productionOrderDocEntry;
//inventoryGenEntry.Lines.BaseLine = 0;

inventoryGenEntry.Lines.Quantity = process.Quantity;
int result = inventoryGenEntry.Add();
if (result != 0)
{
Console.WriteLine($"Error: {company.GetLastErrorDescription()}");
Console.WriteLine($"Error: {company.GetLastErrorCode()}");
}
else
{
Console.WriteLine("Késztermék bevételezés sikeresen rögzítve a termelési rendeléshez!");
}
}
else
{
Console.WriteLine("Nem található cikk a jelentéshez");
}
}
else
{
SAPbobsCOM.Documents inventoryGenEntry = (SAPbobsCOM.Documents)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInventoryGenEntry);
docEntry = recordSet.Fields.Item("DocEntry").Value.ToString();
docEntryInt = int.Parse(docEntry);
found = inventoryGenEntry.GetByKey(docEntryInt);
Console.WriteLine($"DocEntry InventoryGenEntry: {docEntryInt}, Found: {found}");
SAPbobsCOM.Items item = (SAPbobsCOM.Items)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
if (item.GetByKey(process.Material))
{
if (inventoryGenEntry.GetByKey(docEntryInt)) // A megfelelő sor alapján betöltjük a ProductionOrder objektumot
{
bool lineExists = false;
for (int i = 0; i < inventoryGenEntry.Lines.Count; i++)
{
inventoryGenEntry.Lines.SetCurrentLine(i);

if (inventoryGenEntry.Lines.ItemCode == process.Material.ToString())
{
lineExists = true;
break; // No need to continue checking
}
}

if (!lineExists)
{
inventoryGenEntry.Lines.Quantity = process.Quantity; // Bevett mennyiség

// Kapcsolat a termelési rendeléshez
inventoryGenEntry.Lines.BaseEntry = productionOrderDocEntry; // Termelési rendelés DocEntry
inventoryGenEntry.Lines.BaseType =(int)SAPbobsCOM.BoObjectTypes.oProductionOrders; // Alap dokumentum típusa

int result = inventoryGenEntry.Update();
if (result != 0)
{
Console.WriteLine($"Error: {company.GetLastErrorDescription()}");
}
else
{
Console.WriteLine("Késztermék bevételezés sikeresen rögzítve a termelési rendeléshez!");
}
}
}
}
}
}

The above is my code, and it always throws the same error, the employee is not exist or inactive.
"Error: (59001) [59/1/DocEntry/57294] * Nem létezo vagy inaktív dolgozóra nem lehet rögzíteni bizonylatot!
Error: -1116"
But I checked and there is an employee for my user which is loged in by the DI API, 
I also tried the InventoryGenEntry.DocumentOwner = 44 which is the userid in OUSR, and OHEM table too, but got the same error.

Accepted Solutions (1)

Accepted Solutions (1)

Baranyai_Csaba
Explorer
0 Likes

inventoryGenEntry.Reference2 = "employeeId" was the missing line

Answers (0)