Dynamic Code (.NET SDK) schedule to close Production Orders Answered
I'm running some basic code in a Universal function to schedule closing of completed Production Orders. Whilst this code works perfectly in Visual Studio and test compiles OK in the Universal function, when it's run with the scheduler nothing happens.
No errors but no updated closed Production orders either?
SAP Version 9.2 PL 5
Boyum Version 2017.0.6.0
Dynamic Code as follows:
string query = "SELECT DISTINCT OWOR.DocEntry FROM OWOR WHERE OWOR.[Status] = 'R' AND OWOR.[PlannedQty] = OWOR.CmpltQty AND (OWOR.DocEntry NOT IN (SELECT DocEntry FROM WOR1 WHERE DocEntry = OWOR.DocEntry AND WOR1.PlannedQty <> WOR1.IssuedQty))";
SAPbobsCOM.ProductionOrders OWOR = (SAPbobsCOM.ProductionOrders) company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oProductionOrders);
SAPbobsCOM.Recordset rs = (SAPbobsCOM.Recordset)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
rs.DoQuery(query);
SAPbobsCOM.Recordset rs = (SAPbobsCOM.Recordset)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
rs.DoQuery(query);
while (rs.EoF == false)
{
int docEntry = (int) rs.Fields.Item("DocEntry").Value;
if (OWOR.GetByKey(docEntry))
{
OWOR.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposClosed;
int result = OWOR.Update();
string message = company.GetLastErrorDescription();
{
int docEntry = (int) rs.Fields.Item("DocEntry").Value;
if (OWOR.GetByKey(docEntry))
{
OWOR.ProductionOrderStatus = SAPbobsCOM.BoProductionOrderStatusEnum.boposClosed;
int result = OWOR.Update();
string message = company.GetLastErrorDescription();
}
rs.MoveNext();
}
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(OWOR);
System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
Comments
3 comments
Hello David,
Since this is an advanced question, in this case you need to contact your local partner to obtain this support. Unfortunatelly we don't provide Dynamic Code support.
Solved
1. It's missing a line that raises an error when result <> 0, hence why no error.
2. Production Orders couldn't be updated because the user for the scheduler did not have authorization to the document series group.
Thanx, just what we needed. But I am not so familiar with .NET so I just copied and pasted your code, but I missed the code for the error handling. What do I need to complete the code with?
Please sign in to leave a comment.