Saturday, April 14, 2012

Next Document Number Web Service using eConnect

Below is sample code for creating custom Web Service using eConnect for Next Document Number.




using Microsoft.Dynamics.GP.eConnect;





[WebMethod]

public string NextSopDocumentNumber(string TransactionType, string salesDocID)

{

GetNextDocNumbers sopTransNumber = new GetNextDocNumbers();

string nextTransactionNumber = string.Empty;

try

{

///string sConnectionString = ConfigurationManager.ConnectionStrings["GpeConnectConnectionString"].ToString();

string sConnectionString = ="server=YourServerName;database=YourDatabaseName;Integrated Security=SSPI;persist security info=False

switch (TransactionType)

{

case "SalesQuote":

nextTransactionNumber = sopTransNumber.GetNextSOPNumber(IncrementDecrement.Increment, salesDocID, SopType.SOPQuote, sConnectionString);

break;



case "SalesOrder":

nextTransactionNumber = sopTransNumber.GetNextSOPNumber(IncrementDecrement.Increment, salesDocID, SopType.SOPOrder, sConnectionString);

break;



case "SalesInvoice":

nextTransactionNumber = sopTransNumber.GetNextSOPNumber(IncrementDecrement.Increment, salesDocID, SopType.SOPInvoice, sConnectionString);

break;



case "SalesReturn":

nextTransactionNumber = sopTransNumber.GetNextSOPNumber(IncrementDecrement.Increment, salesDocID, SopType.SOPReturn, sConnectionString);

break;



case "SalesBackOrder":

nextTransactionNumber = sopTransNumber.GetNextSOPNumber(IncrementDecrement.Increment, salesDocID, SopType.SOPBackOrder, sConnectionString);

break;



}



return nextTransactionNumber;

}

catch (Exception ex)

{// If an error occurs, diplay the error information to the user

throw ex;

}

finally

{

sopTransNumber.Dispose();

}
}



Below are eConnect schemas to get other transaction type Next Doucment Number.
http://msdn.microsoft.com/en-us/library/ff623613.aspx



To Rollback Transactions Number:

 

             [WebMethod]

        public void RollBackMyDocumentNumber(string strTransactionType, string strDocNumber)

        {

           DocumentRollback TransRollback = new DocumentRollback();

 

           string sConnectionString = ConfigurationManager.ConnectionStrings["GpeConnectConnectionString"].ToString();

             

            try

            {

                switch (strTransactionType)

                {

                        case "SOP":

                                    TransRollback .Add(TransactionType.SOP, strDocNumber);

                                    break;

                    case "Adjustment": //Adjustment

                        TransRollback.Add(TransactionType.IVTrans, strDocNumber);

                        break;

                    case "IVTransfer":

                        TransRollback.Add(TransactionType.IVTransfer, strDocNumber);

                        break;

                    case "POPReceipt":

                        TransRollback.Add(TransactionType.POPReceipt, strDocNumber);

                        break;

                }

               

            }

            catch (Exception ex)

            {// If an error occurs, diplay the error information to the user

                throw ex;

            }

            finally

            {

                TransRollback.Dispose();

            }
 
Below is more details on RollBackDocument
 

Feel free to email me if you need any further assistance or please share your code for same.

Happy coding!!!
Thanks
Sandip