Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Update Sales Order and order item table using eConnect

(0) ShareShare
ReportReport
Posted on by 25

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

  • Tim Wappat Profile Picture
    Tim Wappat 5,701 on at
    RE: Update Sales Order and order item table using eConnect

    Add a line.

    salesHdr.CUSTNMBR = "OCCUST_914";

    before the line...

    salesHdr.SOPTYPE = 2;

    Tim.

  • Suggested answer
    Craig Fuller Profile Picture
    Craig Fuller 409 on at
    RE: Update Sales Order and order item table using eConnect

    I'm totally going out on a limb here as I don't know eConnect but glancing through your post and reading the error returned, don't you need to specify the order number in the header section as well?

    Like:

    salesHdr.SOPNUMBE = "ORD0128840";

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,419 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,492 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans