Working on pre-post MD for Inventory Adjustments and getting error trying to query the DB for info. Any ideas on this error?
Code:
/// DB Tables to query on
Erp.Tables.PartPlant PartPlant;
Erp.Tables.Person Person;
/// Grab data row to work with
var dsInventoryQtyAdjRow = Epicor.Customization.Bpm.EnumerableExtensions.GetSingleRow(ds.InventoryQtyAdj, "ds.InventoryQtyAdj"); // Use Epicor std widget logic
///*** THIS IS CAUSING THE ERROR
var tsEMailAddress = (from rowPartPlant in this.Db.PartPlant
join rowPerson in this.Db.Person on new { Key0 = rowPartPlant.Company, Key1 = rowPartPlant.PersonID } equals new { Key0 = rowPerson.Company, Key1 = rowPerson.PersonID}
where (rowPartPlant.Company == callContextClient.CurrentCompany
&& rowPartPlant.Plant == callContextClient.CurrentPlant
&& rowPartPlant.PartNum == (dsInventoryQtyAdjRow.PartNum))
select new
{
EMailAddress=rowPerson.EMailAddress,
}).FirstOrDefault().EMailAddress; // get toAddress from partplant.person field or default to <Plant>ALERT@company.com if not found.
Error when executes:
Ice.Common.EpicorServerException: BPM runtime caught an unexpected exception of 'NullReferenceException' type.
See more info in the Inner Exception section of Exception Details. ---> System.NullReferenceException: Object reference not set to an instance of an object.
I believe you’re getting the error because of the following portion:
}).FirstOrDefault().EMailAddress; // get toAddress from partplant.person field or default to <Plant>ALERT@company.com if not found.
I would remove the .EmailAddress
Or do this:
/// DB Tables to query on
Erp.Tables.PartPlant PartPlant;
Erp.Tables.Person Person;
/// Grab data row to work with
var dsInventoryQtyAdjRow = Epicor.Customization.Bpm.EnumerableExtensions.GetSingleRow(ds.InventoryQtyAdj, "ds.InventoryQtyAdj"); // Use Epicor std widget logic
///*** THIS IS CAUSING THE ERROR
var tsEMailAddress = (from rowPartPlant in this.Db.PartPlant
join rowPerson in this.Db.Person on new { Key0 = rowPartPlant.Company, Key1 = rowPartPlant.PersonID } equals new { Key0 = rowPerson.Company, Key1 = rowPerson.PersonID}
where (rowPartPlant.Company == callContextClient.CurrentCompany
&& rowPartPlant.Plant == callContextClient.CurrentPlant
&& rowPartPlant.PartNum == (dsInventoryQtyAdjRow.PartNum))
select rowPerson.EMailAddress).FirstOrDefault() ??
"<Plant>ALERT@company.com"; // get toAddress from partplant.person field or default to <Plant>ALERT@company.com if not found.
I know the record I’m testing actually has a correct email address attached, but I’m only getting null from the db query, just not sure why getting null versus the record?
Your change just gave me the fallback data but the query came back null when it should have had my email address.
This is under MD: Erp.InventoryQtyAdj.SetInventoryQtyAdj > Pre-Processing
I ran a Error Info box and all the variables are there and correctly set.
Just the Db.PartPlant & Db.Person join lookup are not providing data back. Just get null. The ds is for collecting all the other data points from the Quantity Adjustment to provide alerts when they occur and they are all present in the dataset. Only grabbing the email address to find out who to notify is providing the NULL.
Well, thanks to @Doug.C !!! I found out too many hours with too little sleep is a bad thing. I thought I had placed the Planner code in Test and had not I was querying in linqpad against live for the data item.