I am trying to create a BPM and use C# code to copy ttPartTran.Character01 to PartLot.Character01.
I am struggling with how to do this. Here is the code that I have right now. It saves in epicor without errors however it does not appear to be saving the data.
using(var txscope1=IceDataContext.CreateDefaultTransactionScope())
{
var ttPartTran_xRow=(from ttPartTran_Row in ttPartTran where string.Compare(ttPartTran_Row.Company,“ITL123456”,true)==0 select ttPartTran_Row).FirstOrDefault();
It occurred to me that this BPM is being triggered for the Job Receipt to Inventory and there may be two ttPartTran records. Is that why this is not working?
If anyone could help I would certainly appreciate it.
Thank you for the suggestion. I get the following error message:
Server Side Exception
There is at least one compilation error.
Exception caught in: Epicor.ServiceModel
Error Detail
Description: There is at least one compilation error.
Details:
Error CS0103: The name ‘PartLot_Row’ does not exist in the current context [ReceiveMfgPartToInventory.Post.SaveInfoToPartLo.cs(119,16)]
Program: Epicor.Customization.dll
Method: PrepareException
Line Number: 99
Column Number: 13
using(var txscope1=IceDataContext.CreateDefaultTransactionScope())
{
var ttPartTran_xRow=(from ttPartTran_Row in ttPartTran where string.Compare(ttPartTran_Row.Company,“ITL123456”,true)==0 select ttPartTran_Row).LastOrDefault();
Thanks to everyone that helped with this - as I mentioned I am not a programmer - so I struggle with the syntax. However I feel like if I can get a simple example working - I can change the table and field names to get the same thing done for other scenarios.
I would appreciate any additional coding/formatting advice from the group.
Hey Dave,
It looks like you are making use of the code converter that Epicor provides for assistance, this is fine to get a general idea of how the flow goes but the code it generates its wholly inefficient and slow, I would be careful putting code generated by the converter in a production system.
The code below should work, a few things to note, always make sure you are working on the temp records that are either Updated or Added in 10.1 Epicor added a Added() and Updated() method to temp records which you can use. Otherwise you’ll have to compare the RowMod
Using accessors to get to the UDFields is recommended in the Temp Row, it has the advantage of giving you some syntax checking because they are typed specific.
Also when you are referring to a UD field in the Db.Context you can address those fields directly (typed) since they are generated as part of the data model when the data model is regenerated.
The transaction scope is usually redundant and not needed unless you are doing a transaction in post processing which is outside of the current transaction scope. You will need to always call DB.Validate when you are updating the DB Tables, though Epicor does that automatically for you in the background (still be a good citizen and clean up yourself)
Try this and see if it works (it should though I can’t test it), its a little simpler than the code generated by the converter.
Mr Gomez: Thanks for the Code.
I tried your version and it works (no surprise there).
I must admit I am confused by the syntax. What is the
ttPartTran.Where(pt => pt.Updated() || pt.Added())
Where did the “pt” come from? and what does it stand for? Is it shortcut for “PartTran”? is pt a variable that I can change to pq if I am using the PartQty table?
I am feeling a little more confident about the C# stuff. Most of what I have to do is simple copy this field to this table kind stuff and you have helped immensely.
I can only hope I will be able to return the favor some day.
pt is sort of an input parameter, its a variable you can declare it to be anything you want, zz if you like. It’s basically a function that will return true or false depending on how your expression (in this case pt.Updated() || pt.Added()) evaluates.