BAQ/dashboard with LINQ query filtering?

I’d like to create a BAQ or dashboard (or any type of search tool) that uses C# to help further filter down results. I’d like the C# code to have access to parameters and then apply some logic to filter results of a BAQ. Is this possible?

You would use a post processing BPM on the get list method. Remove the rows that you want to use.

one way is to turn your BAQ into an UPDATABLE BAQ… then you can go in and add UBAQ BPM logic in the post processing of the query. Any logic you put here is C# done after the query is complete.
BUT I would also say that this causes extra work. For example, the initial BAQ would return back all the rows, but then you would be removing some of those rows. Seems like it would be better to put the filter on the initial Query so that all that work is done back on the SQL Server before it is transmitted back.

Thanks for the response. Normally I’d use SQL query filters but in this case I want to do something more complicated that I think is more easily managed in C#. I was hoping to get a simple example to get me started. How would I write something that looks like this:


I know this is wrong, but how would the syntax actually look for this? If I have some parameter called “Parameter1” and I’m trying to filter based on PartNum field

Is this just an example? or is that what you are actually filtering on? That can be easily accomplished in the BAQ.

It is just an example. I’m not sure where to pull the parameters or how to update the table. Could you provide proper syntax for this example? It will be enough to get me started.
The real problem requires several regex groups and some conditions

So you have to loop through your results, and remove rows (backwards, because your list if going to be getting shorter). This is how you remove rows. Do your check in the if statement.

have to might be too strong of wording. This is one way to do it.

So it’s a bit different than what you asked but could also be an alternate solution. Here’s something I messed with recently using a BAQ with Rest (RestSharp) and getting what I wanted with linq.

        public void CallBAQ()
            var client = new RestClient("https://{epicor}/{instance}/api/v2/odata/{Company}");
            client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
            client.Authenticator = new HttpBasicAuthenticator("{username}", "{password}");

            var request = new RestRequest($"BaqSvc/{baqName}/Data?api-key={apiKey}", Method.GET);

            var queryResult = client.Execute<string>(request).Data;

            Newtonsoft.Json.Linq.JObject obj = Newtonsoft.Json.Linq.JObject.Parse(queryResult);

            var results =
                (from p in obj["value"]
                 select (string)p[$"{field}"]) //ex. JobHead_PartNum
                .OrderBy(p => p);

Basically I wanted to use my BAQ and find a distinct list of the parts in alphabetical order.

Thanks, I am able to pull results now. The only thing I’m struggling with now is getting the value entered by the user for the parameters. It seems to be stored somewhere in ttQueryParameter - I’m able to get the correct parameterID from here but cannot figure out where I’d get the value. Does any one know how to get the value from here? I don’t see any Value field or GetValue method unfortunately.

Usually the normal workaround for that is to make a calculated field(s) that just houses the parameter(s), and then you can refer to the row in the TTResults.

1 Like

Thanks for the help, I did eventually find a way to extract the parameter values. I had to use the ttExecutionParameter object to get it.

That works too. I didn’t mention that one, because that object doesn’t show up in all of the BAQ methods, so depending on what you’re doing where, it can be a pain.

oo ok I will have to keep that in mind. If it’s not available then the calculated field approach also works. Thanks

Check out this thread. It goes over all of that.