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.
Hard coding still returns āNoRecSalesRepā.
So I guess the code is structured right.
Just canāt get the query to return data that I know is there.
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