I am trying to change/update the due date of a production order in SAP B1 with the code below:
public static void ChangeDueDateForProductionOrder(SAPB1Credentials credentials, int poAbsEntry, DateTime dueDate)
{
DebugLogger.Log(credentials.CompanyDB, $"Changing due date for production order '{poAbsEntry}' to '{dueDate.ToString(C_DATE_FORMAT_NL)}'.");
using (var sap = new SAPB1Connection(credentials))
{
ProductionOrders productionOrder = sap.Company.GetBusinessObject(BoObjectTypes.oProductionOrders);
if(productionOrder.GetByKey(poAbsEntry))
{
productionOrder.DueDate = dueDate;
if (productionOrder.Update() != 0)
{
var message = $"Error while changing due date for '{poAbsEntry}' to '{dueDate.ToString(C_DATE_FORMAT_NL)}', the following error is given '{sap.Company.GetLastErrorDescription()}'.";
DebugLogger.Log(credentials.CompanyDB, message);
throw new Exception(message);
}
}
else
throw new Exception($"PoId '{poAbsEntry}' does not exists.");
}
}
However, I am getting the following error:
Error while changing due date for '145' to '11-09-2016', the following error is given 'Field cannot be updated (ODBC -1029)'.
And the error SAP gives is:
Field cannot be updated (ODBC -1029)
Additional information:
- It is a new production order that has the status
Planned
. - Creation date is
Today
. - Due date I am trying to change it to is
Today + 5 days
. - The Id (AbsEntry) for the production order is
145
. - SAP Business One 9.1
- Yes, I can alter the due date in the SAP B1 GUI without problems.
Short, Self Contained, Correct (Compilable), Example
The code below gives me the exact same error. Replaced connection settings with ??
.
using System;
using SAPbobsCOM; // Reference to SAP B1 DI SDK (32-bit)
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var credentials = new SAPB1Credentials
{
Server = "??",
CompanyDB = "??",
Username = "??",
Password = "??"
};
SAPbobsCOM.Company sap = new SAPbobsCOM.Company();
sap.Server = credentials.Server;
sap.DbServerType = credentials.ServerType;
sap.CompanyDB = credentials.CompanyDB;
sap.UserName = credentials.Username;
sap.Password = credentials.Password;
sap.language = credentials.Language;
sap.UseTrusted = credentials.UseTrusted;
var returnCode = sap.Connect();
if (returnCode != 0)
{
var error = sap.GetLastErrorDescription();
throw new Exception(error);
}
ProductionOrders productionOrder = sap.GetBusinessObject(BoObjectTypes.oProductionOrders);
if (productionOrder.GetByKey(145))
{
productionOrder.DueDate = DateTime.Now.AddDays(5);
if (productionOrder.Update() != 0)
{
var error = sap.GetLastErrorDescription();
throw new Exception(error);
}
}
else
throw new Exception($"PoId does not exists.");
}
public class SAPB1Credentials
{
public string Server { get; set; }
public string CompanyDB { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public BoSuppLangs Language { get; set; } = BoSuppLangs.ln_English;
public BoDataServerTypes ServerType { get; set; } = BoDataServerTypes.dst_MSSQL2008;
public bool UseTrusted { get; set; } = false;
}
}
}
What am I missing, and why do I get this error?