Creating Sales Order through WebServices in E9

Hi @surendrapal, for the line-level, apparently GetNewOrderDtl would be suitable but, it looks like I can’t call it as it expects a valid OrderNum as one of the parameters and at that time Order has not been created yet so there is no corresponding OrderNum that I can specify. Look at my code example, that method is commented out and there is a comment.

SalesOrderDataSetTypeOrderDtl soDSDtl = new SalesOrderDataSetTypeOrderDtl();
//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;

once you save header detail you will have order number use that one.

Hi @surendrapal, that approach won’t work. I tried to do it in that way but it will create a header first and then will create another header with the same info along with detail(s).

However, I found a specific method that actually speaks for itself. It’s called SubmitNewOrder it accepts an array of objects like OrderHed, OrderDtl, OrderRel, OrderRelTax, OrderHedMsc and others that might be related to an order. I tried to use that method but when I am trying to submit a new order with populated OrderHed, OrderDtl, OrderRel objects it will return Object reference is not set to an instance of an object error and you can’t do anything about it. I tried different approaches and ways, tried to populate as many fields as I can but no luck. All the data I was using is legit and exists and available in Epicor. I suspect that WebServices API might’ve not been finished or broken or I am missing something but after spending weeks on this particular problem I just do not see what’s wrong.

here is a webservice function in .NET that creates sales order header and details.

Might help, might not.

 private Boolean ProcessOrder(SalesOrderTransfer NewOrder)
        {
            //Create Epicor Link
            //Process the Orderfile
            try
            {
                using (var session = GetSessionID())
            {
            
                using (var OrderProxy = GetOrder(session))
                {
                    Erp.BO.SalesOrderDataSet sods = new Erp.BO.SalesOrderDataSet();

                    //When we have more customers we will need to set the vaule differently???
                    bool blnOut;
                    string strResponseMsg;
                    string strCreditShipAction;
                    string strDisplayMsg;
                    string strCompliantMsg;
                    string strResponseMsgOrdRel;

                    /*This sets the defaults for each customer*/
                    var identity = (ClaimsIdentity)User.Identity;
                    Claim claimCustNum = identity?.FindFirst("CustomerNum");
                    Claim claimCustId = identity?.FindFirst("CustomerID");
                    Claim claimDefaultFOB = identity?.FindFirst("DefaultFOB");
                    Claim claimTermsCode = identity?.FindFirst("TermsCode");
                                        
                    string strCustId = claimCustId.Value;
                    int intCustomerNum = int.Parse(claimCustNum.Value);
                    string strDefaultFOB = claimDefaultFOB.Value;
                    string strTermsCode = claimTermsCode.Value;


                    int intSalesOrder = 0;
                    int intDetailCount = 0;
                    
                    foreach (var salesorder in NewOrder.SalesOrderCreate)
                    {

                        //if (salesorder.OrderHeader.NeedByDate.ToString() == "") break;
                        //We first need to create the OrderHeader
                        //this should only be done once per file
                        if (intSalesOrder == 0)
                        { 
                            //Create New Order
                            OrderProxy.GetNewOrderHed(sods);

                            intSalesOrder = sods.OrderHed[0].OrderNum;
                            //Default Fields Created
                            sods.OrderHed[0].Company = "HI";
                            sods.OrderHed[0].CustNum = intCustomerNum;
                            sods.OrderHed[0].CustomerCustID = strCustId;
                            sods.OrderHed[0].BTCustNum = intCustomerNum;
                            sods.OrderHed[0].ShipToCustNum = intCustomerNum;
                            OrderProxy.ChangeSoldToID(sods);
                            sods.OrderHed[0].FOB = strDefaultFOB;
                            sods.OrderHed[0].OrderDate = DateTime.Now;
                            sods.OrderHed[0].ShipViaCode = salesorder.OrderHeader.ShipViaCode.ToString();  //"FX1";
                            sods.OrderHed[0].TermsCode = strTermsCode;
                            sods.OrderHed[0].UseOTS = true;
                            
							OrderProxy.ChangeHedUseOTS(sods);
							sods.OrderHed[0]["Date01"] = DateTime.Now;


                            //Fields from first record of file
                            //DateTime? myDateTime =  DateTime.ParseExact(salesorder.OrderHeader.NeedByDate.ToString(), "MM/dd/yyyy", null);

                            if (salesorder.OrderHeader.NeedByDate.ToString() == "")
                            {
                                    sods.OrderHed[0].NeedByDate = Convert.ToDateTime("01/01/2010");
                            }
                            else
                            {
                                    sods.OrderHed[0].NeedByDate = Convert.ToDateTime(salesorder.OrderHeader.NeedByDate.ToString());
                            }

                            OrderProxy.ChangeNeedByDate(sods, "OrderHed");

                            sods.OrderHed[0].OrderComment = salesorder.OrderHeader.OrderComment.ToString();
                            sods.OrderHed[0].ShipComment = salesorder.OrderHeader.ShipComment.ToString();
                            sods.OrderHed[0].OTSAddress1 = salesorder.OrderHeader.OTSAddress1.ToString();
                            sods.OrderHed[0].OTSAddress2 = salesorder.OrderHeader.OTSAddress2.ToString();
                            sods.OrderHed[0].OTSAddress3 = salesorder.OrderHeader.OTSAddress3.ToString();
                            sods.OrderHed[0].OTSCity = salesorder.OrderHeader.OTSCity.ToString();
                            sods.OrderHed[0].OTSContact = salesorder.OrderHeader.OTSContact.ToString();
                            sods.OrderHed[0].OTSCountryNum = int.Parse(salesorder.OrderHeader.OTSCountryNum.ToString());
                            //sods.OrderHed[0].OTSFaxNum = row["OTSFaxNum"].ToString();
                            sods.OrderHed[0].OTSName = salesorder.OrderHeader.OTSName.ToString();
                            sods.OrderHed[0].OTSPhoneNum = salesorder.OrderHeader.OTSPhoneNum.ToString();
                            //sods.OrderHed[0].OTSResaleID = row["OTSResaleID"].ToString();
                            sods.OrderHed[0].OTSState = salesorder.OrderHeader.OTSState.ToString();
                            sods.OrderHed[0].OTSZIP = salesorder.OrderHeader.OTSZIP.ToString();
                            sods.OrderHed[0].PONum = salesorder.OrderHeader.PONum.ToString();
                            sods.OrderHed[0].RequestDate = Convert.ToDateTime(salesorder.OrderHeader.RequestDate.ToString());
                            sods.OrderHed[0]["ShortChar02"] = salesorder.OrderHeader.CustomerPONum.ToString();
                            sods.OrderHed[0]["ShortChar03"] = salesorder.OrderHeader.CustomerCustId.ToString();
                            sods.OrderHed[0]["CustRef_c"] = salesorder.OrderHeader.CustomerRefInfo.ToString();
                            sods.OrderHed[0]["NeedTrackingSent_c"] = 1;
                            sods.OrderHed[0]["OrderContact_c"] = salesorder.OrderHeader.OTSContact.ToString();


                                OrderProxy.MasterUpdate(true, true, "Orderhed", intCustomerNum, intSalesOrder, true, out blnOut, out strResponseMsg, out strCreditShipAction, out strDisplayMsg, out strCompliantMsg, out strResponseMsgOrdRel, sods);

                            intSalesOrder = sods.OrderHed[0].OrderNum;
                        }

                        foreach (var line in salesorder.LineItems)
                        { 
                            //Create new Lines for the order
                            OrderProxy.GetNewOrderDtl(sods, intSalesOrder);
                            intDetailCount = sods.OrderDtl.Count - 1;

                            //sods.OrderDtl[intDetailCount].PartNum = line.PartNum.ToString();
                            //sods.OrderDtl[intDetailCount].PartNumPartDescription = line.PartNum.ToString();

                            OrderProxy.ChangePartNum(sods, false, "");

                            if (salesorder.OrderHeader.NeedByDate.ToString() == "")
                            {
                                sods.OrderDtl[intDetailCount].NeedByDate = Convert.ToDateTime("01/01/2010");
                            }
                            else
                            {
                                sods.OrderDtl[intDetailCount].NeedByDate = Convert.ToDateTime(salesorder.OrderHeader.NeedByDate.ToString());
                            }

                            OrderProxy.ChangeNeedByDate(sods, "OrderDtl");

                            sods.OrderDtl[intDetailCount].RequestDate = Convert.ToDateTime(salesorder.OrderHeader.RequestDate.ToString());
                            sods.OrderDtl[intDetailCount].SellingQuantity = decimal.Parse(line.SellingQuantity.ToString());
                            // sods.OrderDtl[intDetailCount].OrderLine = int.Parse(line.OrderLine.ToString());
                            sods.OrderDtl[intDetailCount].XPartNum = line.CustXPartNum.ToString();
                            //sods.OrderDtl[intDetailCount].XPartNum = "(" + line.CustXPartNum.ToString() + ")";
                                OrderProxy.ChangeXPartNum(sods);
                            OrderProxy.ChangeCommissionable(sods);
                            //Need to call masterupdate not update 
                            OrderProxy.MasterUpdate(true, true, "OrderDtl", intCustomerNum, intSalesOrder, true, out blnOut, out strResponseMsg, out strCreditShipAction, out strDisplayMsg, out strCompliantMsg, out strResponseMsgOrdRel, sods);
                            //need to test
                            //if (line.Warehouse.ToString() == "Service")
                            //{ 
                                sods.OrderRel[intDetailCount].WarehouseCode = line.Warehouse.ToString();
                                OrderProxy.ChangeORelWarehouse(sods);
                                OrderProxy.MasterUpdate(true, true, "OrderRel", intCustomerNum, intSalesOrder, true, out blnOut, out strResponseMsg, out strCreditShipAction, out strDisplayMsg, out strCompliantMsg, out strResponseMsgOrdRel, sods);
                            //}
                        }

                        if (intSalesOrder != 0)
                        {
                            sods.OrderHed[0].UserChar1 = "PRINT";
                            sods.OrderHed[0].RowMod = "U";
                            //OrderProxy.Update(sods);
                            OrderProxy.MasterUpdate(true, true, "Orderhed", intCustomerNum, intSalesOrder, true, out blnOut, out strResponseMsg, out strCreditShipAction, out strDisplayMsg, out strCompliantMsg, out strResponseMsgOrdRel, sods);
                        }
                    }
                     // Email Ken that file was processed with Order and Line details
                     //SendMail();
                 }
                    
            }
            return true;
            }
            catch (Exception e)
            {

                Console.WriteLine("{0} Exception caught.", e);
                return false;

            }
        }  //private Boolean ProcessOrder(SalesOrderTransfer NewOrder)

Hi Ken,

Well done. Thanks for sharing your code. It seems like you are doing this through a dll Epicor.Mfg.BO.SalesOrder and Epicor.Mfg.IF.ISalesOrder? As I understand this is not an option when you want to post order through WSDL. I am doing something like this:

First of all here is what SalesOrderDataSetType class is accepting:

SalesOrderDataSetType ds = new SalesOrderDataSetType();
SalesOrderDataSetTypeOrderHed soDSHed = new SalesOrderDataSetTypeOrderHed();
SalesOrderDataSetTypeOrderDtl soDSDtl = new SalesOrderDataSetTypeOrderDtl();
SalesOrderDataSetTypeOrderRel soDSRel = new SalesOrderDataSetTypeOrderRel();

//Populate OrderHed fields
soDSHed.OrderNum = 0;
soDSHed.CustomerCustID = "1";
soDSHed.OrderDate = DateTime.Today;
soDSHed.RequestDate = DateTime.Today;
soDSHed.NeedByDate = DateTime.Today;
soDSHed.ShipToNum = "2";
soDSHed.ShipViaCode = "UPS";
soDSHed.OrderComment = "TestOrderComment";
soDSHed.FOB = "Test";
soDSHed.WebOrder = false;
soDSHed.TermsCode = "PP";
soDSHed.TaxRegionCode = "TEST";
soDSHed.TotalCharges = 20.30m;
soDSHed.TotalShipped = 2;
soDSHed.SalesRepCode1 = "TS";
soDSHed.BTCustNum = 1;
soDSHed.PONum = "Test";

ds.SalesOrderDataSet[0] = soDSHed;

//Populate OrderDtl fields
soDSDtl.POLine = "1";
soDSDtl.OrderLine = 1;
soDSDtl.PartNum = "408115";
soDSDtl.XPartNum = "";
soDSDtl.LineDesc = "TestDecr222";
soDSDtl.SellingQuantity = 2.0m;
soDSDtl.SalesUM = "EACH";
soDSDtl.UnitPrice = 15.0m;
soDSDtl.Reference = "Reftest";
soDSDtl.Commissionable = true;
soDSDtl.DiscountPercent = 10.00m;
soDSDtl.WarehouseCode = "MAIN";
soDSDtl.MktgCampaignID = "TES";
soDSDtl.SalesCatID = "TES";

ds.SalesOrderDataSet[1] = soDSDtl;

//Populate OrderRel fields. You have to include these fields, otherwise, you will get keys are missing in a parent table error.
soDSRel.Company = "TEST";
soDSRel.OrderNum = latestOrderNumber+1;
soDSRel.OrderLine = 1;

ds.SalesOrderDataSet[2] = soDSRel;

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

This is how I am populating objects and trying to send them. I noticed that Epicor is pretty responsive and gives a legit error if you are missing one of the required fields as I got with ShipViaCode. It’s not mentioned in the documentation lol, but it returned me an error that ShipViaCode is required.

I think you need to update the sales header to get the id. then use that sales id of the newly created order to create the line.

Sorry Ken, what kind of id are you talking about?

Alex have you done a trace in Epicor on how an order is created?
You should be calling the order creation process approximately in this fashion

GetNewOrderHed
ChangeCustomerInfo
Update
GetNewOrderDtl
SetLineDetail
Update

You can’t (at least not reliably) send the header and lines at the same time because of dependency issues, header needs to exist before the lines are added.
Do a trace in Epicor and then use my Trace tool (or Notepad) to look at the trance and see what data needs to be changed, send on every one of the calls.

1 Like

I meant OrderNum

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.