Creating Sales Order through WebServices in E9

Hi Jose,

Yes, I’ve done a trace and tried to use methods like shown there. Except I used SubmitNewOrder method to create Header which does it with no errors and creates a proper header with proper data. It’s not on a list of methods though but, I am assuming you have to create a Header somehow first at least.

Then, I used methods like shown in the trace I got which are:

  1. GetNewOrderHed
  2. SubmitNewOrder
  3. OnChangeofSoldToCreditCheck
  4. ChangeSoldToID ----- this one returned a warning that Header did not change. So I commented it out in code.
  5. ChangeCustomer ----- this one returned a warning that Header did not change. So I commented it out in code.
  6. GetList
  7. MasterUpdate
  8. GetNewOrderDtl
  9. ChangePartNumMaster
  10. ChangeSellingQtyMaster
  11. MasterUpdate

It will create a header but, not a detail and I do not get any errors back. That’s why I did give up on this way and tried to go with what WSDL documentation says about SubmitNewOrder.

You need to use the ordernum from the GetNewOrderHed when you call the GetNewOrderDtl

You are calling the GetNewOrderDtl with no order reference, which is why its blank.

Of course I am doing that. Number 6, GetList. I am doing like so:
var list= soService.GetList(“TEST”, “OrderNum=143991”, 100, 0, callContextIn, out bool morePages, out callContextOut);

I am changing order number in that where clause manually for now but, it works and returns me a new latest OrderNum. I am using that OrderNum then for detail. Epicor will return you an error if you are missing or have an invalid OrderNum.

I am trying to help. Lets look at your code then to be on the same page.

The first part looks ok. Not sure how your ordernums are set, but I am guessing there is something that takes the 0 and creates one.

SalesOrderDataSetType ds = new SalesOrderDataSetType();

SalesOrderDataSetTypeOrderHed soDSHed = new SalesOrderDataSetTypeOrderHed();

ds = soService.GetNewOrderHed("TEST", ds, callContextIn, out callContextOut);
soDSHed.Company = "TEST";
soDSHed.OrderNum = 0;
soDSHed.CustNum = 1;
soDSHed.CustomerCustID = "TEST";
soDSHed.ShipViaCode = "UPSG";

There is no update of the header yet. think you should do that.

Don’t worry about the list as that is not needed here.

The next line creates a empty SalesOrderDataSet.
SalesOrderDataSetTypeOrderDtl soDSDtl = new SalesOrderDataSetTypeOrderDtl();
We don’t really want that. We want a detail line for the newly created order header.

This commented out line is the correct call, you need to use the ordernum from the header, which needs to be updated first.

//ds = soService.GetNewOrderDtl("TEST", ds, 0, callContextIn, out callContextOut);//This guy is commented out as it won't accept 0 as OrderNum and would return an error that valid OrderNum is required.
soDSDtl.Company = "TEST";
soDSDtl.OrderNum = 0;
soDSDtl.OrderLine = 1;
soDSDtl.PartNum = "6.WD8";
soDSDtl.CustNum = 1;
soDSDtl.SellingQuantity = 2.0m;
                
ds.SalesOrderDataSet[0] = soDSHed;
Trace.WriteLine("Line 9 -----------------");
ds.SalesOrderDataSet[1] = soDSDtl;
Trace.WriteLine("Line 10 -----------------");

soService.SubmitNewOrder("TEST", ds, callContextIn, out callContextOut);

Trace.WriteLine("Line 11 -----------------");
1 Like

I know you are trying to help and I appreciate your time an effort. Do not think I am trying to be a freak or something.

Zero is OrderNum that you supply in E9 and it will generate next OrderNum on Save of a header. That’s also what Epicor says when I am trying to enter the next OrderNum:
image

And I guess you mentioned that I need to create a Header first and then use a valid OrderNum to from that Header to create detail for that Header and that’s what I am doing. Let me share the latest code here:

SalesOrderDataSetType ds = new SalesOrderDataSetType();
//Populating Header fealds
SalesOrderDataSetTypeOrderHed soDSHed = new SalesOrderDataSetTypeOrderHed();

ds = soService.GetNewOrderHed("TEST", ds, callContextIn, out callContextOut);
soDSHed.Company = "TEST";
soDSHed.OrderNum = 0;
soDSHed.CustNum = 1;
soDSHed.CustomerCustID = "TEST";
soDSHed.ShipViaCode = "UPSG";

ds.SalesOrderDataSet[0] = soDSHed;

soService.SubmitNewOrder("TEST", ds, callContextIn, out callContextOut);//This will create only a header. After this call new order with OrderNum and other info already in Epicor.

soService.OnChangeofSoldToCreditCheck("TEST", 0, "TESTCUST", ds, callContextIn, out string creditLimit, out bool cont, out callContextOut);

//soService.ChangeSoldToID("TEST", ds, callContextIn, out callContextOut); you can comment this one as it will return a warning that Header did not changed

//soService.ChangeCustomer("TEST", ds, callContextIn, out callContextOut); you can comment this one as it will return a warning that Header did not changed

soService.MasterUpdate("TEST", checkForResponse, "OrderHed", 1, 143991, weLicensed, ds, callContextIn, out weLicensed, out string RespMsg, out string DispMasg, out string complMsg, out string tt, out callContextOut);

var list = soService.GetList("TEST", "OrderNum=143991", 100, 0, callContextIn, out bool morePages, out callContextOut); // Where clause is OrderNum=143991 is for just retrieve the latest one and not all of them for now.

//Grabbing an OrderNum value
OrderHedListDataSetTypeOrderHedList listDataSet = new OrderHedListDataSetTypeOrderHedList();
int validOrderNum = 0;
foreach (var item in list.OrderHedListDataSet)
{
	if (item is OrderHedListDataSetTypeOrderHedList)
	{
		listDataSet = (OrderHedListDataSetTypeOrderHedList)item;
		validOrderNum = listDataSet.OrderNum;
	}
	Trace.WriteLine("Line 9 -----------------" + listDataSet.OrderNum);
}

//Populating Detail fields
SalesOrderDataSetTypeOrderDtl soDSDtl = new SalesOrderDataSetTypeOrderDtl();
ds = soService.GetNewOrderDtl("TEST", ds, validOrderNum, callContextIn, out callContextOut);
soDSDtl.Company = "TEST";
soDSDtl.OrderNum = validOrderNum;
soDSDtl.OrderLine = 1;
soDSDtl.PartNum = "6.WD8";
soDSDtl.CustNum = 1;
soDSDtl.SellingQuantity = 1;
soDSDtl.LineType = "PART";

string partNum = soDSDtl.PartNum;
bool SubPartExists = false;
bool isPhantom = false;
string uomCode = "";

Trace.WriteLine("Line 2 -----------------");

soService.ChangePartNumMaster("TEST", ref partNum, ref SubPartExists, ref isPhantom, ref uomCode, "", "", false, false, false, true, true, true, ds, callContextIn, out string cDeleteComp, out string questStr, out string cWarningMess,out bool multyMatch, out bool promptToExpBOM, out string cConfigPart, out string cSubPart, out string explBOM, out string cMsgType, out bool multiSubsAvail, out bool runOutQtyAvail, out callContextOut);

Trace.WriteLine("Line 3 -----------------");

soService.ChangeSellingQtyMaster("TEST", ds, soDSDtl.SellingQuantity, false, false, true, true, false, true, partNum, "","","","EA", 1.0m,callContextIn, out string pcMess, out string pcNeqQty,out string opWarning, out string cSellingQuantity, out callContextOut);

Trace.WriteLine("Line 4 -----------------");

ds.SalesOrderDataSet[1] = soDSDtl;

Trace.WriteLine("Line 5 -----------------");

soService.MasterUpdate("TEST", checkForResponse, "OrderDtl", 1, validOrderNum, weLicensed, ds, callContextIn, out weLicensed, out string RespMsgDtl, out string DispMasgDtl, out string complMsgDtl, out string ttDtl, out callContextOut);

Trace.WriteLine("Line 6 -----------------");

Methods calls occurs in a proper order like TraceLog shows. Except for SubmitNewOrder.
Let me know if you need more info.

Step 1 :- Add Service Reference.
image

Step 2:- Add using

using xxxx.SalesOrderService;

note :- xxxx mean your namespace of the project.

Step 3: use below code to insert Sales order header and line.

SalesOrderServiceClient proxy = new SalesOrderServiceClient();
            proxy.ClientCredentials.UserName.UserName = "epicor";
            proxy.ClientCredentials.UserName.Password = "epicor";
            string loginOptions = "CompanyID=EPIC06;PlantID=Mfgsys;LanguageID=enu";
            var callContext = new CallContextDataSetType();
            var salesOrderDS = new SalesOrderDataSetType();
            var lContinue = false;
            var cCreditLimitMessage = string.Empty;
            var iOrderNum = 0;
            var iCustID = "Addison";
            var lcheckForResponse = true;
            var lweLicensed = true;
            var cTableName = "OrderHed";
            var cResponseMsg = string.Empty;
            var cDisplayMsg = string.Empty;
            var cCompliantMsg = string.Empty;
            var cResponseMsgOrdRel = string.Empty;
            var iCustNum = 0;

            salesOrderDS = proxy.GetNewOrderHed(out callContext, loginOptions, salesOrderDS, callContext);
            salesOrderDS = proxy.OnChangeofSoldToCreditCheck(out cCreditLimitMessage, out lContinue, out callContext, loginOptions, iOrderNum, iCustID, salesOrderDS, callContext);
            salesOrderDS = proxy.ChangeSoldToID(out callContext, loginOptions, salesOrderDS, callContext);
            salesOrderDS = proxy.ChangeCustomer(out callContext, loginOptions, salesOrderDS, callContext);
            iCustNum = Convert.ToInt32(salesOrderDS.OrderHed.FirstOrDefault().CustNum);
            salesOrderDS.OrderHed.FirstOrDefault().PONum = "TestPO123";
            salesOrderDS = proxy.MasterUpdate(out lContinue, out cResponseMsg, out cDisplayMsg, out cCompliantMsg, out cResponseMsgOrdRel, out callContext, loginOptions, lcheckForResponse, cTableName, iCustNum, iOrderNum, lweLicensed, salesOrderDS, callContext);
            iOrderNum = Convert.ToInt32(salesOrderDS.OrderHed.FirstOrDefault().OrderNum);
            if (iOrderNum > 0)
            {
                salesOrderDS = proxy.GetNewOrderDtl(out callContext, loginOptions, salesOrderDS, iOrderNum, callContext);                
	            var partNum = "001_MPCons"; // Set Line PartNum
	            var lSubstitutePartExist = false;
	            var lIsPhantom = false;
	            var uomCode = string.Empty;
	            var sysRowID = string.Empty;
	            var rowType = string.Empty;
	            var salesKitView = false;
	            var removeKitComponents = false;
	            var suppressUserPrompts = false;
	            var getPartXRefInfo = true;
	            var checkPartRevisionChange = true;
	            var checkChangeKitParent = true;
		        var cDeleteComponentsMessage = string.Empty;
		        var questionString = string.Empty;
		        var cWarningMessage = string.Empty;
		        var multipleMatch = false;
		        var promptToExplodeBOM = false;
		        var cConfigPartMessage = string.Empty;
		        var cSubPartMessage = string.Empty;
		        var explodeBOMerrMessage = string.Empty;
		        var cMsgType = string.Empty;
		        var multiSubsAvail = false;
                var runOutQtyAvail = false;
                cTableName = "OrderDtl";
                salesOrderDS = proxy.ChangePartNumMaster(loginOptions, ref partNum, ref lSubstitutePartExist, ref lIsPhantom, ref uomCode, out cDeleteComponentsMessage, out questionString, out cWarningMessage, out multipleMatch, out promptToExplodeBOM, out cConfigPartMessage, out cSubPartMessage, out explodeBOMerrMessage, out cMsgType, out multiSubsAvail, out runOutQtyAvail, out callContext, sysRowID, rowType, salesKitView, removeKitComponents, suppressUserPrompts, getPartXRefInfo, checkPartRevisionChange, checkChangeKitParent, salesOrderDS, callContext);
                
	            var ipSellingQuantity = 10; //Set Line Qty
	            var chkSellQty = false;
	            var negInvTest = false;
	            var chgSellQty = true;
	            var chgDiscPer = true;
	            var lKeepUnitPrice = true;
                var pcPartNum = partNum;
	            var pcWhseCode = string.Empty;
	            var pcBinNum = string.Empty;
	            var pcLotNum = string.Empty;
	            var pcDimCode = "EA";
	            var pdDimConvFactor = 1;
		        var pcMessage = string.Empty;
		        var pcNeqQtyAction = string.Empty;
		        var opWarningMsg = string.Empty;
		        var cSellingQuantityChangedMsgText = string.Empty;
                salesOrderDS = proxy.ChangeSellingQtyMaster(out pcMessage, out pcNeqQtyAction, out opWarningMsg, out cSellingQuantityChangedMsgText, out callContext, loginOptions, salesOrderDS, ipSellingQuantity, chkSellQty, negInvTest, chgSellQty, chgDiscPer, suppressUserPrompts, lKeepUnitPrice, pcPartNum, pcWhseCode, pcBinNum, pcLotNum, pcDimCode, pdDimConvFactor, callContext);
                salesOrderDS = proxy.ChangeUnitPrice(out callContext, loginOptions, salesOrderDS, callContext);

                salesOrderDS.OrderDtl.Where(OD => OD.RowMod == "A").FirstOrDefault().DocDspUnitPrice = 150; // Set Unit Price
                salesOrderDS = proxy.MasterUpdate(out lContinue, out cResponseMsg, out cDisplayMsg, out cCompliantMsg, out cResponseMsgOrdRel, out callContext, loginOptions, lcheckForResponse, cTableName, iCustNum, iOrderNum, lweLicensed, salesOrderDS, callContext);
            }

note :- above code for WCF service

2 Likes

For Web Services.

SalesOrderService proxy = new SalesOrderService();
            UsernameOverTransportAssertion userNameAssertion = new
            UsernameOverTransportAssertion();
            userNameAssertion.UsernameTokenProvider = new
            UsernameTokenProvider("epicor", "epicor");
            // Set the policy onto the proxy
            Policy policy = new Policy();
            policy.Assertions.Add(userNameAssertion);
            proxy.SetPolicy(policy);
            var companyID = "EPIC06";
            var callContext = new CallContextDataSetType();
            var salesOrderDS = new SalesOrderDataSetType();
            var lContinue = false;
            var cCreditLimitMessage = string.Empty;
            var iOrderNum = 0;
            var iCustID = "Addison";
            var lcheckForResponse = true;
            var lweLicensed = true;
            var cTableName = "OrderHed";
            var cResponseMsg = string.Empty;
            var cDisplayMsg = string.Empty;
            var cCompliantMsg = string.Empty;
            var cResponseMsgOrdRel = string.Empty;
            var iCustNum = 0;

            salesOrderDS = proxy.GetNewOrderHed(companyID, salesOrderDS, callContext, out callContext);
            salesOrderDS = proxy.OnChangeofSoldToCreditCheck(companyID, iOrderNum, iCustID, salesOrderDS, callContext, out cCreditLimitMessage, out lContinue, out callContext);
            salesOrderDS = proxy.ChangeSoldToID(companyID, salesOrderDS, callContext, out callContext);
            salesOrderDS = proxy.ChangeCustomer(companyID, salesOrderDS, callContext, out callContext);
            var salesOrderHedDS = (SalesOrderDataSetTypeOrderHed)salesOrderDS.SalesOrderDataSet[0];
            
            iCustNum = Convert.ToInt32(salesOrderHedDS.CustNum);
            salesOrderHedDS.PONum = "TestPO123";
            salesOrderDS = proxy.MasterUpdate(companyID, lcheckForResponse, cTableName, iCustNum, iOrderNum, lweLicensed, salesOrderDS, callContext, out lContinue, out cResponseMsg, out cDisplayMsg, out cCompliantMsg, out cResponseMsgOrdRel, out callContext);
            salesOrderHedDS = (SalesOrderDataSetTypeOrderHed)salesOrderDS.SalesOrderDataSet[0];
            iOrderNum = Convert.ToInt32(salesOrderHedDS.OrderNum);
            if (iOrderNum > 0)
            {
                salesOrderDS = proxy.GetNewOrderDtl(companyID, salesOrderDS, iOrderNum, callContext, out callContext);                
	            var partNum = "001_MPCons"; // Set Line PartNum
	            var lSubstitutePartExist = false;
	            var lIsPhantom = false;
	            var uomCode = string.Empty;
	            var sysRowID = string.Empty;
	            var rowType = string.Empty;
	            var salesKitView = false;
	            var removeKitComponents = false;
	            var suppressUserPrompts = false;
	            var getPartXRefInfo = true;
	            var checkPartRevisionChange = true;
	            var checkChangeKitParent = true;
		        var cDeleteComponentsMessage = string.Empty;
		        var questionString = string.Empty;
		        var cWarningMessage = string.Empty;
		        var multipleMatch = false;
		        var promptToExplodeBOM = false;
		        var cConfigPartMessage = string.Empty;
		        var cSubPartMessage = string.Empty;
		        var explodeBOMerrMessage = string.Empty;
		        var cMsgType = string.Empty;
		        var multiSubsAvail = false;
                var runOutQtyAvail = false;
                cTableName = "OrderDtl";
                salesOrderDS = proxy.ChangePartNumMaster(companyID, ref partNum, ref lSubstitutePartExist, ref lIsPhantom, ref uomCode, sysRowID, rowType, salesKitView, removeKitComponents, suppressUserPrompts, getPartXRefInfo, checkPartRevisionChange, checkChangeKitParent, salesOrderDS, callContext,  out cDeleteComponentsMessage, out questionString, out cWarningMessage, out multipleMatch, out promptToExplodeBOM, out cConfigPartMessage, out cSubPartMessage, out explodeBOMerrMessage, out cMsgType, out multiSubsAvail, out runOutQtyAvail, out callContext);
                
	            var ipSellingQuantity = 10; //Set Line Qty
	            var chkSellQty = false;
	            var negInvTest = false;
	            var chgSellQty = true;
	            var chgDiscPer = true;
	            var lKeepUnitPrice = true;
                var pcPartNum = partNum;
	            var pcWhseCode = string.Empty;
	            var pcBinNum = string.Empty;
	            var pcLotNum = string.Empty;
	            var pcDimCode = "EA";
	            var pdDimConvFactor = 1;
		        var pcMessage = string.Empty;
		        var pcNeqQtyAction = string.Empty;
		        var opWarningMsg = string.Empty;
		        var cSellingQuantityChangedMsgText = string.Empty;
                salesOrderDS = proxy.ChangeSellingQtyMaster(companyID, salesOrderDS, ipSellingQuantity, chkSellQty, negInvTest, chgSellQty, chgDiscPer, suppressUserPrompts, lKeepUnitPrice, pcPartNum, pcWhseCode, pcBinNum, pcLotNum, pcDimCode, pdDimConvFactor, callContext, out pcMessage, out pcNeqQtyAction, out opWarningMsg, out cSellingQuantityChangedMsgText, out callContext);

                var salesOrderDtlDS = ((SalesOrderDataSetTypeOrderDtl)salesOrderDS.SalesOrderDataSet[1]);
                salesOrderDtlDS.DocDspUnitPrice = 150; // Set Unit Price
                salesOrderDtlDS.CurrencySwitch = false;
                salesOrderDtlDS.DBRowIdent =  new byte[0];
                salesOrderDS.SalesOrderDataSet[1] = salesOrderDtlDS;
                salesOrderDS = proxy.ChangeUnitPrice(companyID, salesOrderDS, callContext, out callContext);
                salesOrderDS = proxy.MasterUpdate(companyID, lcheckForResponse, cTableName, iCustNum, iOrderNum, lweLicensed, salesOrderDS, callContext, out lContinue, out cResponseMsg, out cDisplayMsg, out cCompliantMsg, out cResponseMsgOrdRel, out callContext);
            }
1 Like

Hi Surendra,

Wow! Thank you so much for these examples. Your Web Services example worked as expected. I will play around with it in order to extrapolate the code so I can submit more information.

Hi Surendra,

I want to say thank you one more time for your Web Services example. I was able to modify and post some additional data, like OTS info and RelTax info which is in my case wha I was looking for. However, it seems like I still can’t get NeedBy field populated even though I tried to specify it like on the screenshot:

This is a screenshot of your code just slightly modified. So I tried to supply NeedBy date in header dataset but that did not work.

Trace shows that we have to call ChangeNeedByDate method. Here is the trace for that method, it’s not complete though:

Here is what that methods accepts for parameters:

May I please ask you to try this one on your environment? Am I calling method incorrectly or in the not proper order?

Thank you,

Alex

user below code


            salesOrderHedDS.NeedByDate = DateTime.Today.AddDays(1);
            salesOrderHedDS.NeedByDateSpecified = true;
            salesOrderDS = proxy.ChangeNeedByDate(companyID, salesOrderDS, cTableName, callContext, out callContext);

Thanks, worked flawlessly.