BPM Pre-processing Method Error

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.
3 Likes

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.

changed to:

... .FirstOrDefault() ?? new { EMailAddress =((callContextClient.CurrentPlant != "MfgSys" ? callContextClient.CurrentPlant:(callContextClient.CurrentCompany=="ZZ"?"ZZZZ":(callContextClient.CurrentCompany=="XX"?"XXXX":"YYYY")))+@"ALRT@company.com") };  

If you run the query in LinqPad or do the SQL equivalent in SSMS, do you get records if you fill in the where values manually?

yes

Works all the ways I tried it which kept throwing me that null error

simplify it, you don’t need that join

I need the person email from the part number…
how do you propose I get it?

Hold on let me look closer, I’m on a phone and distracted, I may have spoken too soon.

I mean only other way is query from subquery same thing as the join rite?

I just tried my code with a part from our PartPlant that has that data defined and I got an e-mail address.

I would do some Debugging/Logging of your variables and see if there is something throwing off your query results.

EDIT: I did it with your original code and got the same results as my code. I think maybe there is something with variable assignment.

Maybe try:

var dsInventoryQtyAdjRow =  ds.InventoryQtyAdj.First();

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.

1 Like

Glad you got it worked out bud.

I was shopping with the wife and forgot to come back.