Hi When I update the sales order and orderLine item using eConnect i get this error.
select * from SOP10100
select * from SOP10200
Microsoft.Dynamics.GP.eConnect.eConnectException
Message : If UpdateExisting is set to 1 than a transaction document number must be provided.
StackTrace : at Microsoft.Dynamics.GP.eConnect.ServiceProxy.CreateEntity(String connectionString, String xml)
at Microsoft.Dynamics.GP.eConnect.eConnectMethods.EntityImportImplementation(String connectionString, String sXML, Boolean isTransaction)
at Microsoft.Dynamics.GP.eConnect.eConnectMethods.CreateEntity(String connectionString, String sXML)
at DynamicsGP.Program.Main(String[] args) in D:\ProjectWork\MST_Finecal_DataMigration_Hiten_4July2019_WIP\DynamicsGPProject\DynamicsGP\DynamicsGP\Program.cs:line 596
Below is my code.
using (eConnectMethods eConnectMethods = new eConnectMethods())
{
try
{
string connectionString = @"data source=10.219.225.154;initial catalog=" + ConfigurationManager.AppSettings["GPDatabaseName"] + ";Integrated Security=SSPI;Persist Security Info=False;";
#region Order Code
Console.WriteLine("Start Creating order.");
DateTimeFormatInfo dateFormat = new CultureInfo("en-US").DateTimeFormat;
SOPTransactionType salesOrder = new SOPTransactionType();
taSopLineIvcInsert_ItemsTaSopLineIvcInsert salesLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
taSopHdrIvcInsert salesHdr = new taSopHdrIvcInsert();
taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] LineItems = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[1];
//List<taSopLineIvcInsert_ItemsTaSopLineIvcInsert> LineItems = new List<taSopLineIvcInsert_ItemsTaSopLineIvcInsert>();
salesLine.CUSTNMBR = "OCCUST_914";
salesLine.SOPTYPE = 2;
salesLine.SOPNUMBE = "ORD0128840";
salesLine.DOCID = "STD ORDER";
salesLine.QUANTITY = 2;
salesLine.ITEMNMBR = "10069266";
salesLine.UNITPRCE = 10;
salesLine.XTNDPRCE = 20;
salesLine.DOCDATE = System.DateTime.Today.ToString("dd/MM/yyyy", dateFormat);
salesLine.NONINVEN = 0;
salesLine.LOCNCODE = "LABELS";
salesLine.ADDRESS1 = "Mekhmandarov street, 72, flat 53";
salesLine.UpdateIfExists = 1;
salesLine.LNITMSEQ = 16384;
salesLine.RecreateDist = 0;
LineItems[0] = salesLine;
salesOrder.taSopLineIvcInsert_Items = LineItems;
salesHdr.SOPTYPE = 2;
salesHdr.DOCID = "STD ORDER";
salesHdr.BACHNUMB = "B1";
salesHdr.DOCDATE = System.DateTime.Today.ToString("dd/MM/yyyy", dateFormat);
salesHdr.CUSTNMBR = "OCCUST_914";
salesHdr.SUBTOTAL = 20;
salesHdr.DOCAMNT = 20;
salesHdr.LOCNCODE = "LABELS";
salesHdr.UpdateExisting = 1;
//salesHdr.USINGHEADERLEVELTAXES = 0;
salesOrder.taSopHdrIvcInsert = salesHdr;
eConnectType eConnect = new eConnectType();
SOPTransactionType[] MySopTransactionType = new SOPTransactionType[1] { salesOrder };
eConnect.SOPTransactionType = MySopTransactionType;
// Serialize the master vendor type in memory.
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xmlSerializer = new XmlSerializer(eConnect.GetType());
// Serialize the eConnectType.
xmlSerializer.Serialize(memoryStream, eConnect);
// Reset the position of the memory stream to the start.
memoryStream.Position = 0;
// Create an XmlDocument from the serialized eConnectType in memory.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(memoryStream);
memoryStream.Close();
Console.WriteLine("Call eConnect method.");
// Call eConnect to process the XmlDocument.
eConnectMethods.CreateEntity(connectionString, xmlDocument.OuterXml);
//string salesOrderDocID = eConnectMethods.CreateTransactionEntity(connectionString, xmlDocument.OuterXml);
//Console.WriteLine("Successfully created sales order {0}.", salesOrderDocID);
Console.WriteLine("Successfully created sales order");
#endregion
#region Customer Code
//InsertUpdateCustomer(objOpenCartCustomers, connectionString, eConnectMethods);
#endregion
}
catch (Exception ex)
{
Console.WriteLine("Error Ocured.");
Console.WriteLine("Exception occured: " + ex.Message);
WriteErrorToFile(ex);
}
finally
{
eConnectMethods.Dispose();
}
}
Please share example if any one have.
*This post is locked for comments