Run Updateable BAQ from customisation [C#]

(Richard Hodges) #1

Hi all

I’ve done some research online and I don’t think what I want to do is possible but I wanted to double check with you guys before I wrote it off.

I’ve currently got a very simple BAQ running in a Customization that returns a SELECT statement and apply’s it to an ultragrid.

This is the code I’ve used:

DynamicQueryAdapter dynamicQueryAdapter = new DynamicQueryAdapter(oTrans);
QueryExecutionDataSet queryExecutionDataSet = dynamicQueryAdapter.GetQueryExecutionParametersByID(“selectBAQ”);
queryExecutionDataSet.ExecutionParameter.AddExecutionParameterRow(“CompanyID”, companyTextBox.Text, “nvarchar”, false, Guid.Empty, “A”);
dynamicQueryAdapter.ExecuteByID(“selectBAQ”, queryExecutionDataSet);
baqUltraGrid.DataSource = dynamicQueryAdapter.QueryResults.Tables[“Results”];

What I’m wondering is, is there a way to run an UPDATE BAQ statement using the DynamicQueryAdapter object (or anything else in the customisations code)?

I’ve got an updateable BAQ set up and when I run the Update in the analyse tab it does work, however when I look at the query phrase in the General tab it’s still a SELECT statement so I’m not sure how I would go about using it in a customisation.

Is it possible to run an UPDATE statement from a BAQ in a similar manner to the one above (so what would happen is I would click a button and then the BAQ would run the UPDATE statement for now, later on I’d add parameters and a textbox for the updated value) or is that not possible?

The reason I’m using a BAQ and not a SqlCommand with the SQL passed in as a string (where I could just write the UPDATE query myself) is because I’m testing the runtime of BAQ’s, so the UPDATE has to be ran through a BAQ.

Many thanks

(Jose C Gomez) #2

Hi @Rik first, you should NEVER do the above. Never in Epicor should you write a SQL Command and or a SQL update command. Everything you do should be via the BOs or UBAQs. Running SQL violates your Epicor support agreement and it is a quick way to get into a lot of pain.

Yes you can run an updatable BAQ from code all you need to do is run a Trace on the BAQ Designer and see what it does / replicate on your code.

(Richard Hodges) #3

Thanks for letting me know, I haven’t done any inline SQL commands yet so I’ll avoid doing that.

I’ve actually solved the issue now but I had no idea you could run a trace on the BAQ Designer too, that’s a good trick to know thanks for your help!


(Jose C Gomez) #4

How did you solve it?


(Richard Hodges) #5

Used a DynamicQueryAdapter to run the query then updated the DynamicQueryAdapter’s QueryResults “Results” table with what I needed updating and then ran the DynamicQueryAdapter’s Update method.