How to set OrderMsc.MiscCode = "myString" via C# customization?

Hi All,

I’m writing my first C# customization to add a Misc Charge and and I’m stumbling over something I suspect is simple. After calling getById(orderNum) and GetNewOrderMsc(orderNum, orderLine) I need to set the OrderMsc.MiscCode = “Tari” and finally MasterUpdate(…). I’ve proven this works via the BL tester but I’m a bit unsure how to set the OrderMsc.MiscCode variable in C#. Below is a code snippet, could someone point me in the right direction please?

int orderNum = int.Parse(edvOrderDtl.dataView[edvOrderDtl.Row][“OrderNum”].ToString());
int line = int.Parse(edvOrderDtl.dataView[edvOrderDtl.Row][“OrderLine”].ToString());
int custNum = int.Parse(edvOrderDtl.dataView[edvOrderDtl.Row][“CustNum”].ToString());

SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(oTrans);
adapterSalesOrder.BOConnect();

try
{
if(adapterSalesOrder.GetByID(orderNum) && adapterSalesOrder.GetNewOrderMsc( orderNum, line ))
{
adapterSalesOrder.SalesOrderData.OrderMsc[“MiscCode”] = “Tari”;

Resulting Errors:

Error: CS1502 - line 313 (638) - The best overloaded method match for ‘Epicor.Mfg.BO.SalesOrderDataSet.OrderMscDataTable.this[int]’ has some invalid arguments
Error: CS1503 - line 313 (638) - Argument ‘1’: cannot convert from ‘string’ to ‘int’

TIA,
Eddie

You can use something like this. Did you take a look at using a BPM for this? I typically recommend doing that for this type of enhancement unless there is a good requirement not to do that.

adapterSalesOrder.SalesOrderData.Tables["OrderMsc"].Rows[0]["MiscCode"] = "Tari";
1 Like

Thanks so much, that worked and I can now add Misc Line Charges! We chose to use a C# customization because we are currently on 9.05.605 and are in the process of upgrading to E10. I understand the C# customizations will get uplifted without an issue, where a Progress BPM would most likely require human intervention.

The end goal is we are looking to add a Misc Line charge for every line on a Sales Order automatically to cover increasing material costs due to Tariffs. The recommendation was this would be easier to implement in a C# customization.

Thanks again, this forum is has a lot of amazingly helpful people.

Thanks,
Eddie

1 Like

Is there a resource somewhere I could have looked to answer this question myself. How can I discover the methods, properties, etc exist for a SalesOrderAdapter(I looked at the Object Explorer and it doesn’t seem to have any of this information - I’m using version 9.05.605)?

My specific question is how do the OrderMsc.Rows relate to lines? I know what line was just changed and I only care to look at the OrderMsc.Rows for the current line. This is because the customization triggers on the Update() method, which I find is triggered each time a line changes in SO Entry. I had hoped by looping through adapterSalesOrder.SalesOrderData.Tables[“OrderMsc”].Rows I’d be looking at all Misc Line charges for the current line but I’m finding it’s for all lines on the SO.

I think everyone has their own preference on this one but I think there is some basic knowledge that can be found in the online user guides such as the SDK Guides, Business Object Reference Guide, and Advanced Customization Guide, etc.
I find myself using Tracing and then manually performing the steps in Epicor before coding. This provides you the methods, sequence, and data structures needed to perform the same actions in code. I also use BL Tester quite a bit to help validate some of this.
Once outside of those steps I de-compile quite a bit to better understand when I am stuck on something. I know the resident de-comp expert @Chris_Conn is quite possibly the fastest de-comp’er I have ever seen and is always willing to help :slight_smile:
Along with all these things I think this forum is a great resource for learning (millions of examples) and getting help.
if you trace the steps you are doing and review that trace I am 100% confident you will get your answers.

1 Like

Thanks Dan. I’m familiar with tracing, the BL Tester, and have a few dev docs(BOMethods_905.pdf), but not decompilers for Epicor so I will look into that.

Epicor development just seem like such a hunt and peck guessing game when you get started(w/ experience I’m sure development speeds up as you build up more code you can reference), but from looking at other recent posts from some of the experts(@bart_ella) on the forum, it just seems like that is the way it is due to lack of documentation and Epicor is working on improving the situation.

Thanks for the kind words @danbedwards . I <3 Decompilers.

@embedded There are several decompilers available that are all very similar, here are the main ones:
ILSPy - free, awesome
JetBrains DotPeek - free, not my favorite
RedGate .NET Reflector - paid, not too shabby

You should start with the guides and references - they set up the concepts and patters mostly used
Tracing and BL Tester - are great for the next step, since you need to know what your looking for
Decompile - your last step to get the finer details about whats happening under the hood

A few tips:

  • An adapter is just a fancy wrapper for a BO/Contract
  • When decompiling - start by focusing on public methods/objects - sure the invisible private ones are helpful for better understanding, but for your purposes, public is where it is at.
  • It will take some time before you start understanding the namespaces all of your classes are organized in, but once you do, it’s much easier to hunt stuff down

More specific to your question, you can drill down as mentioned below to look at the DataSets, this will show you all of the tables in a DataSet (in my picture - LaborDataSet), in my picture, I drilled down even further into the LaborDtlRow definition to see the fields (and types) avialable

Hope this helps get you started.

5 Likes

Thanks so much this is what I’m looking for!

@chris_conn sorry not sure if I should start a new thread… Thanks for the pointers, I have ILSpy installed and it looks like I needed to open the dll file with the AD in the name for the adapter (I first opened the BO but your screenshot was helpful to see it was the wrong dll). I’m slowly making my way around by starting with working code then looking to see how I could have figured this out on my own with the decompiler. As an example I started with a working line of code - adapterSalesOrder.SalesOrderData.OrderDtl.Rows.Count. I found SalesOrderData is a SalesOrderDataset instance, and in looking in the implementation I think I found OrderDtl is an OrderDtlDataTable, but I’m having a hard time finding Rows… Anyway, I’ve been using the SOAP APIs for a couple of years and I have similar challenges where I have datasets that I don’t understand ahead of time so I typically use print_r(serialize / stringify an object) in PHP to look at what is returned to me and for the most part the data structure is pretty intuitive and I can figure out what I’m looking for. I’m fairly new to C# and right now wishing I could just run print_r(adapterSalesOrder.SalesOrderData), so I can see what the data structure looks like. Is there a way to do this in C# as a quick and dirty debug tool?

PS I’ll keep digging into the debugger long term but right now I’d love to see what the data looks like for debugging / discovery.

Probably the easiest way to see the row structure is to either use BAQ, pull the table in and the fields will be listed (along with types). Also, you can use the Data Dictionary.