Proper way to use BPM to update OrderRel

,

We are seeing an issue where BuyToOrder on a quote line does not transfer over to the orderrel when flipping the quote to an order. It does for quote FROM and order but not TO an order. We have a ticket open with Epicor at this moment.

We are trying to get around the issue by setting the BuyToOrder manually in a BPM. I am relativly new to Epicor, especially BPMs. This is what I have come up with so far but is it the correct wayt to update the database in Epicor?

    foreach( var quoteDtl in (from qd in Db.QuoteDtl
    			join od in Db.OrderDtl.DefaultIfEmpty() on new {qd.Company, qd.QuoteNum, qd.QuoteLine} equals new {od.Company,od.QuoteNum,od.QuoteLine}
    			join orel in Db.OrderRel.DefaultIfEmpty() on new {od.Company,od.OrderNum,od.OrderLine} equals new {orel.Company,orel.OrderNum,orel.OrderLine}
    			join p in Db.Part.DefaultIfEmpty() on new {qd.Company} equals new { p.Company}
    			where qd.ShortChar01 == p.PartNum
    			join pp in Db.PartPlant.DefaultIfEmpty() on new {p.Company, p.PartNum} equals new {pp.Company, pp.PartNum}
    			where (orel.BuyToOrder == false) && (orel.OpenRelease == true) &&( od.OrderNum == orderNum) && pp.BuyToOrder == true
    			select new {SiteBuyToOrder = pp.BuyToOrder,
    						OrelBuyToOrder = orel.BuyToOrder,
    						orel.OrderRelNum,
    						orel.OrderLine,
    						orel.OrderNum})) {
    	foreach(var orderRel in (from OrderRel_Row in Db.OrderRel
    													where (OrderRel_Row.OrderNum == quoteDtl.OrderNum) && (OrderRel_Row.OrderLine == quoteDtl.OrderLine) && (OrderRel_Row.OrderRelNum == quoteDtl.OrderRelNum)
    													select OrderRel_Row)) {
    				orderRel.BuyToOrder = true;
    	}		
    }

Are you intending to update every quote / orderrel in the system every time?
Right now you are looping through every ordeal in the system every time.I assume you’d want to do this only once for the current order?

@josecgomez
correct. Just the current order.

ok, currently you are looping through everything in the system, what method are you running this on?

Also you are joining all Quote Details to all the Parts in the same company which I suspect you also don’t want to do.

@josecgomez
I am running on Quote => Create Order.

I am not even sure that is the correct one.

@josecgomez
no to all parts in whole company.

@josecgomez

the main question i have is , “is there a way i am supposed to use epicor business objects to make my change to the database within my bmp to do this?”

Is the Buy To Order checkbox not getting checked on the order release if the selected part is a non-stock purchased part?

@tkoch

Correct.

Yes, you should do a trace on an order and manually set the BuyToOrder then call those BO’s in the Post Proc BPM

Yes, something like this on Post Processing should do it. “The right way”

using(var so = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))
{
    var ds = so.GetByID(orderNum);
    for(int i=0; i> ds.OrderRel.Count;i++)
    {
        if(!ds.OrderRel[i].BuyToOrder)
        {
            ds.OrderRel[i].RowMod="U";
            so.ChangeOrderRelBuyToOrder(true,ref ds);
            so.Update(ref ds);
        }
    }
}

@josecgomez

thanks Jose. Being a noob here, how did you know to call Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.SalesOrderSvcContract>(Db))? I did a trace and don’t see any of that code anywhere mentioned.

Trace tells you the BO, to figure out how to call it you need the docs for the Customization User Guide, the ICE Tools Guide and the Programmers Guide (from EpicWeb)

@josecgomez

I have the customization user guide and the ice tools guide but where do I find the programmers guide, “business object reference guide”? I can’t find it on epicweb for 10.1.500.

https://epicweb.epicor.com/doc/Docs/Epicor10_ConvertedCode_ProgrammingGuide_101400.pdf#search=Converted%20Code

1 Like

@josecgomez

thanks for your help Jose. I am attempting to add what you have given me but i keep getting this error when i enable and save the directive:

Server Side Exception

There is at least one compilation error.

Exception caught in: Epicor.ServiceModel

Error Detail

Description: There is at least one compilation error.
Details:
Error CS0433: The type ‘Erp.Tablesets.ETCAddrValidationTableset’ exists in both ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.SalesOrder.dll’ and ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.Quote.dll’ [CustomizationAdapter.cs(264,30)]
Error CS0433: The type ‘Erp.Tablesets.QuoteQtyTable’ exists in both ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.SalesOrder.dll’ and ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.Quote.dll’ [CreateOrder.CommonTypes.cs(281,33)]
Error CS0433: The type ‘Erp.Tablesets.HedTaxSumTable’ exists in both ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.SalesOrder.dll’ and ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.Quote.dll’ [CreateOrder.CommonTypes.cs(301,33)]
Error CS0433: The type ‘Erp.Tablesets.PartSubsTable’ exists in both ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.SalesOrder.dll’ and ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.Quote.dll’ [CreateOrder.CommonTypes.cs(306,33)]
Error CS0433: The type ‘Erp.Tablesets.TaxConnectStatusTable’ exists in both ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.SalesOrder.dll’ and ‘d:\Epicor\Websites\EpicorTest10\Server\Assemblies\Erp.Contracts.BO.Quote.dll’ [CreateOrder.CommonTypes.cs(311,33)]

I am using CreateOrder on Quote.

UGH… yeah this is a known issue… in short your are sh*t out of luck… IN reality you can get around it with an external DLL… but that’s painful.
Basically there are some BO’s that utilize the same DataSets and those datasets were not defined via Interface, rather the same exact dataset was created in BOTH DLL’s.
This is a known issue we’ve discussed in the past. You are going to have to either use an External DLL to invoke the method or not use the BO in this particular method. :frowning:

1 Like

@josecgomez
Well that really sucks. I guess we are going the route of external dll’s. Thanks for you help.

BTW this was solved in 600+

2 Likes