web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Update line item in salesOrder

(0) ShareShare
ReportReport
Posted on by 4
I want to update quantity line by using Software Development Kits ( SDk )  for Microsoft Dynamics GP 2018  
 
when update line that occured  an error :

 Error : Violation of PRIMARY KEY constraint 'PKAAG20000'. Cannot insert duplicate key in object 'dbo.AAG20000'. The duplicate key value is (357112).

why? and how fix error ??

used Code : 
 try
            {
                string connectionStringGP = @/Data Source=.;Initial Catalog=test ;persist security info=False;/;
                
                using (eConnectMethods eConnect = new eConnectMethods())
                {
                    
                    eConnectType eConnectTypeSalesTransaction = new eConnectType();
                    eConnectOut eConnectOut1 = new eConnectOut()
                    {
                        DOCTYPE = /Sales_Transaction/, // Specify the type of document you want to retrieve
                        OUTPUTTYPE = 2, // Specify output type: 2 for XML
                        INDEX1FROM =/CON/2300034/ , ///CON/2400006/  // Specify the start index
                        INDEX1TO =/CON/2300034/ ,// /CON/2400006/// Specify the end index
                        FORLIST = 1, // Specify 1 to retrieve a list
                    };
                    eConnectTypeSalesTransaction.RQeConnectOutType = new RQeConnectOutType[] { new RQeConnectOutType() { eConnectOut = eConnectOut1 } };
                    string xmlSopTransaction = SerializeObject(eConnectTypeSalesTransaction);
                    //Call the GetEntity method to retrieve data
                    string response = eConnect.GetEntity(connectionStringGP, xmlSopTransaction);
                    //Console.WriteLine($///r/Data retrieved First :/{response} //r/ ________________________________________________/);
                   
                    //  Deserialize the XML string into objects
                    Root root = DeserializeFromXml<Root>(response);
                    //  Update the object properties as needed
                 
                    #region Update Sales Transaction 
                    taSopHdrIvcInsert sopHdrIvc = new taSopHdrIvcInsert();
                    sopHdrIvc.SOPNUMBE = root.EConnect.SOTrans.SOPNUMBE;
                    sopHdrIvc.SOPTYPE = root.EConnect.SOTrans.SOPTYPE;
                    sopHdrIvc.DOCID = root.EConnect.SOTrans.DOCID;
                    sopHdrIvc.CUSTNMBR = root.EConnect.SOTrans.CUSTNMBR;
                    sopHdrIvc.DOCDATE = root.EConnect.SOTrans.DOCDATE;
                    sopHdrIvc.BACHNUMB = root.EConnect.SOTrans.BACHNUMB;
                    sopHdrIvc.UpdateExisting = 1;
                    taSopLineIvcInsert_ItemsTaSopLineIvcInsert sopLine = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert();
                    sopLine.SOPTYPE = root.EConnect.SOTrans.Lines[0].SOPTYPE;
                    sopLine.CUSTNMBR = root.EConnect.SOTrans.CUSTNMBR;
                    sopLine.QUANTITY = 9; //9root.EConnect.SOTrans.Lines[0].QUANTITY;
                    sopLine.DOCDATE = root.EConnect.SOTrans.DOCDATE;
                    sopLine.ITEMNMBR = root.EConnect.SOTrans.Lines[0].ITEMNMBR;
                    sopLine.SOPNUMBE = root.EConnect.SOTrans.Lines[0].SOPNUMBE;
                    sopLine.LNITMSEQ = root.EConnect.SOTrans.Lines[0].LNITMSEQ;
                    sopLine.LOCNCODE = root.EConnect.SOTrans.Lines[0].LOCNCODE;
                    sopLine.UpdateExisting=1;
                   
                    taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] sopLines = new taSopLineIvcInsert_ItemsTaSopLineIvcInsert[] { sopLine };
                    eConnectType updateSOPTransactionType = new eConnectType();
                    updateSOPTransactionType.SOPTransactionType = new SOPTransactionType[]
                    {
                        new SOPTransactionType()
                        {
                            taSopHdrIvcInsert = sopHdrIvc,
                            taSopLineIvcInsert_Items = sopLines,
                            
                            
                        }
                    };
                    var updatedXmlString = SerializeObject(updateSOPTransactionType);
                    #endregion
                    var updatedResponse = eConnect.UpdateTransactionEntity(connectionStringGP, updatedXmlString);
                    //var updatedResponse = eConnect.DeleteTransactionEntity(connectionStringGP, updatedXmlString);
                     string response2 = eConnect.GetEntity(connectionStringGP, xmlSopTransaction);
                    Console.WriteLine($///r/Data retrieved After :/{response2} //r/ _______________________________/);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(/Error: / + ex.Message);
            }
 

 
Categories:
I have the same question (0)
  • Judy Profile Picture
    Microsoft Employee on at
    Hi, for the error message, you cannot enter a second PK that has the same value.
    You can debug the code to look at your values and how you insert them to the database.
  • Saleh Abdelrahem Profile Picture
    4 on at
    why SDK try to insert in table 'dbo.AAG20000' but I want to update line in an sales order .
    sopLine.UpdateExisting=1;
     
    this flag that known that , 1 if exist line update it , 2 if not exist line insert it 
    by using this function , 'UpdateTransactionEntity',  
     
       var updatedResponse = eConnect.UpdateTransactionEntity(connectionStringGP, updatedXmlString);

    also when try delete a line item , occured the same error  : 
     
    Error : Violation of PRIMARY KEY constraint 'PKAAG20000'. Cannot insert duplicate key in object 'dbo.AAG20000'. The duplicate key value is (357112).

     
    I don't understand , how fix this error ?
  • Suggested answer
    Lisa at AonC.com Profile Picture
    958 Super User 2025 Season 2 on at
  • Saleh Abdelrahem Profile Picture
    4 on at
    I know this to handle ,table by sql query update .

    but I want to handle this error by using SDK .
     
    how do this?
     
    help

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans