Using the methods from BL Tester

How do I use the methods from BL tester (like GetDataSetForTree) within a data directive?
I have a data directive that triggers from jobHead and I’m using the execute custom C# item to generate a file that pulls information about each assembly in a job and dumps it into a file that another program can read.

Here is some of the code I am trying to use.
var job = ttJobHead.FirstOrDefault();
DataSet currJob = new DataSet(GetDatasetForTree(Convert.ToString(job.JobNum), 0, 0, true, “”));
When I check the syntax it says “The name ‘GetDatasetForTree’ does not exist in the current context”

I have tried a bunch of different usings and references and changing it to stuff like JobEntry.GetDatasetForTree() but it never recognizes the method.

Here is an example.

var jeSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>(Db);
var jh = jeSvc.GetDatasetForTree(“123”, 0, 0, true, “”);
var job = jh.JobHead.FirstOrDefault();
string partNum = job[“PartNum”].ToString();

Make sure to add the appropriate reference as well.

What does the Db stand for? database?
When I try using that I get the error that “The type arguments for method ‘ServiceRenderer.GetService(bool)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.”
So I changed it to var jeSvc = Ice.Assemblies.ServiceRenderer.GetService(true); but it doesnt recognize Db.
The forum formatting doesn’t like my less than and greater than signs so here is what I put

I pasted the wrong example

Replace line 1 with this

Erp.Contracts.JobEntrySvcContract jeSvc = null;

It’s not liking that it’s being set to null. When the getDataSet method runs it throws a null reference exception.
What can I set jeSvc to? It doesn’t let me initialize a new Erp.Contracts.JobEntrySvcContract() since it’s an interface.

Here are the steps.

var jeSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.JobEntrySvcContract>(Db);
var jh = jeSvc.GetDatasetForTree(“123”, 0, 0, true, “”);
var job = jh.JobHead.FirstOrDefault();
string partNum = job[“PartNum”].ToString();
Epicor.Customization.Bpm.InfoMessage.Publish(partNum);

1 Like

I can see that var jeSvc = Ice.Assemblies.ServiceRenderer.GetService(Db); is going to fix the null reference exception but Db it still can’t find the type or namespace. Althought the Epicor editor highlights it purple so it recognizes it in some way. I have all the using statements and references you put.

I got it to work, because of the formatting of these posts I couldn’t see part of that statement.
This is what needs to go in the < >

Good catch, I sometimes forget about that when I paste in code. I updated the initial answer so it displays correctly.

I can never pass a discussion on Data Directives without putting out my standard warning to people just sticking their toes in the water in this area. Data Directives are very powerful and handy. They are also the fastest way to grind your server to a halt. Remember this is row by row by row processing. If you embed a ton of logic in here then anytime you are trying to save you can really slow things down.
You need to get work done so not criticizing, just go in with eyes open and ideally measure the impact you just put on the system by adding a trace and monitoring.

2 Likes