Trying to use a UD Field in the where clause of Linq statement in a BPM.
I have searched and found some good information here, but still cannot get the results I am looking for.
In our case we use Character02 on the Customer table to hold an additional SalesRepCode to link to the SalesRep table. I have BPM (Pre) on Update for Customer. I can get the results I am looking for when I link Compnay & SalesRepCode from the ttCustomer table to the SalesRep table. But when I try to use Company & Character02 to link to Company & SalesRepCode, the syntax check works but I get a Ling error from the UI.
BPM runtime caught an unexpected exception of ‘NotSupportedException’ type.
See more info in the Inner Exception section of Exception Details.
LINQ to Entities does not recognize the method ‘System.Object get_Item(System.String)’ method, and this method cannot be translated into a store expression.
Erp.Tables.SalesRep SalesRep = null;
var ttCustomer_xRow = (from ttCustomer_Row in ttCustomer
where ttCustomer_Row.RowMod == “U”
select ttCustomer_Row).FirstOrDefault();
if (ttCustomer_xRow != null)
{
SalesRep = (from SalesRep_Row in Db.SalesRep
where SalesRep_Row.Company == Session.CompanyID
//&& SalesRep_Row.SalesRepCode == ttCustomer_xRow.SalesRepCode (This Line Wokrs)
//&& SalesRep_Row.SalesRepCode == ttCustomer_xRow[“ShortChar02”]
//&& string.Compare((string)SalesRep_Row.SalesRepCode,(string)ttCustomer_xRow[“ShortChar02”] ,true)==0
select SalesRep_Row).FirstOrDefault();
Linq to Entities depends on which version of Epicor you’re on, but either way UD fields can be tricky. They even sometimes behave differently in different types of directive.
You could save yourself the effort by creating a string variable first, since there’s only a single line, and using that in the Linq instead.
I did try to set a variable (usgin the gui) and pass it to the where clause, but it still choked on me.
Do I simple just declare the string in the C# compiler and assigned it after I the code checks the ttCustomer table? Far from a pro here… appreciate the help.
Not getting any Linq errors… this is a plus.
But I still can’t seem to return the data I am looking for.
I even passed the value of src to a popup… so i know it is getting data.
I can query the table in sql to verify that there should be a record from the Linq query,
But my second query must be coming back null for some reason.
Erp.Tables.SalesRep SalesRep = null;
var ttCustomer_xRow = (from ttCustomer_Row in ttCustomer
where ttCustomer_Row.RowMod == “U”
select ttCustomer_Row).FirstOrDefault();
Just can’t seem to get this one over the goal line.
Appreciate the help… it feels close, but I guess I am just missing something or don’t have the full breadth of skill to find out where this is,
Erp.Tables.SalesRep SalesRep = null;
var ttCustomer_xRow = (from ttCustomer_Row in ttCustomer
where ttCustomer_Row.RowMod == “U”
select ttCustomer_Row).FirstOrDefault();
It certainly looks like it should work. Spaces in the UD field (although the message doesn’t look like it)? The SQL query doesn’t include the check for Company? Otherwise I’m afraid there’s something there I’m not seeing.
Well, it could be that or something simple.
Walking through it…
Are you sure that the customer you are running the BPM against has a ShortChar02 value of “NG”?
Have you cleared the form you’re using to trigger this code? Call Context BPM variable data is kind of icky to work with. Sometimes it clears, sometimes it doesn’t. There’s an article on this forum about when the callcontextBPMdata persists vs. clears…
You could also try instead of using call context variables to create your own BPM variables and explicitly clear them and set them in your code. That would help to simplify I think
So I closed Customer Maintenance, Cleared Client Cache, logged out and back in.
Same result:
I will try to ditch the callContextBPMDate variables… can’t hurt to learn how to skirt them in the future.
Customer table does have NG in ShortChar02 for the CustID i’m testing.
Checked my company and environment… we are solid on that front.
I dumped the callContextBPMData and found your post on pushing our a message in a BPM (thanks).
I swapped the commented line to use the SalesRepCode to in the where clause and ran it successfully.
I toggle back to try use the src variable in the where clause and came up with "NoRecordsSalesRep’ Again