We are working on a web-based api for our customers. We have a BPM setup to hit two endpoints with a couple query string arguments (see below). This functionality works as intended, however only certain customers and certain parts for those customers need to be tracked by our web-based system. We can therefore improve our system by calling the endpoints only if the Customer is setup (boolean UDF) and if the CustXPrt is setup (boolean UDF) rather than every time a package is shipped.
We don’t do much C# dev in house but are pretty confident this will be simple for someone familiar with E10 and C#. Below is what our ShipHead data directive custom code looks like:
// This will call an endpoint to create Transit, InventoryPart, and PartEvent rows inside DB
try
{
var sh = ttShipHead.FirstOrDefault();
var custIsSetup = ?;
var custXPrtIsSetup = ?;
if(sh != null && custIsSetup && CustXPrtIsSetup) {
using(var client = new System.Net.WebClient()) {
var transitCreateUrl = string.Format("http://ourSecretEndpoint?c={0}&p={1}", sh.Company, Convert.ToString(sh.PackNum));
var inventoryCreateUrl = string.Format("http://ourSecretEndpoint?c={0}&p={1}", sh.Company, Convert.ToString(sh.PackNum));
var transitResponse = client.OpenRead(transitCreateUrl);
var inventoryResponse = client.OpenRead(inventoryCreateUrl);
}
}
}
If someone can instruct us on how to retrieve Customer and CustXPrt so that we can test against the UDFs that exist on each that will be very helpful.
you use linq to query tables outside the current dataset(tt). something along the lines of this would work. You can grab the entire customer record as the example shows or specific columns as required.
// gets you the entire record
foreach (var x in ttCustomer)
{
var customer = (from cust in Db.Customer.With(LockHint.NoLock) where cust.Company == x.Company && cust.CustNum == x.CustNum select cust).FirstOrDefault();
}
// gets you specific fields
foreach (var x in ttCustomer)
{
var customer = (from cust in Db.Customer.With(LockHint.NoLock) where cust.Company == x.Company && cust.CustNum == x.CustNum select new { cust.CustID, cust.CustNum, Cust.UDF } ).FirstOrDefault();
}
Thank you rbucek! Very helpful!
Here is the final solution to our issue:
try
{
var sh = ttShipHead.FirstOrDefault();
var shipmentHasARSCustXPrt = false;
var customer = (from cust in Db.Customer.With(LockHint.NoLock)
where cust.Company == sh.Company
&& cust.CustNum == sh.CustNum
&& cust.ARSCustomer_c
select cust).FirstOrDefault();
foreach ( var sd in (from shpdtl in Db.ShipDtl.With(LockHint.NoLock)
where shpdtl.Company == sh.Company
&& shpdtl.PackNum == sh.PackNum
select shpdtl)) {
foreach ( var cxp in (from custxprt in Db.CustXPrt.With(LockHint.NoLock)
where custxprt.Company == sd.Company
&& custxprt.CustNum == sh.CustNum
&& custxprt.PartNum == sd.PartNum
select custxprt)) {
if (cxp.ARSPart_c) {
shipmentHasARSCustXPrt = true;
}
} // end foreach cxp
} // end foreach shpdtl
if(sh != null && customer != null && shipmentHasARSCustXPrt) {
using(var client = new System.Net.WebClient()) {
var transitCreateUrl = string.Format("http://ourEndPoint?c={0}&p={1}", sh.Company, Convert.ToString(sh.PackNum));
var inventoryCreateUrl = string.Format("http://ourEndPoint?c={0}&p={1}", sh.Company, Convert.ToString(sh.PackNum));
var transitResponse = client.OpenRead(transitCreateUrl);
var inventoryResponse = client.OpenRead(inventoryCreateUrl);
}
}
} // end try
catch(Exception ex)
{
// error handling here
// this clause prevents errors from bubbling back up to Epicor to prevent the end user from getting an error if something goes wrong
}