Run Updateable BAQ from customisation [C#]

Here is code I used to exec a UBAQ and add new Rows which I use as my Server File Writer, so I can on-prem write to UNC Paths as the Service Account (Server Side) and not Client Side!

public System.Data.DataSet xyz()
{
       // Declare and create an instance of the Adapter.
       DynamicQueryAdapter adapterDynamicQuery = new DynamicQueryAdapter(this.oTrans);
       adapterDynamicQuery.BOConnect();

       // Declare and Initialize Variables
       string BAQName = "HASO-FileWrite";

       bool more;
       var dqds = adapterDynamicQuery.GetQueryExecutionParametersByID(BAQName);
       var ds = adapterDynamicQuery.GetList(BAQName, dqds, 0, 0, out more);

       // This shows me adding 2 Rows manually, here you would loop through your dataset and add many many rows
       // then you would call .Update once! And then in the BPM you can Combine them all and use
       // WriteAllText to write it out in a single file open. 
       var newRow  = ds.Tables["Results"].NewRow();
       newRow["Calculated_FileName"] = "MyFileName.txt";
       newRow["Calculated_Content"] = "rrrrrra";
       newRow["RowMod"] = "A";
       newRow["SysRowID"] = Guid.NewGuid();
       newRow["RowIdent"] = newRow["SysRowID"].ToString();
       ds.Tables["Results"].Rows.Add(newRow);

       var newRow2  = ds.Tables["Results"].NewRow();
       newRow2["Calculated_FileName"] = " MyFileName.txt";
       newRow2["Calculated_Content"] = "eeeeee";
       newRow2["RowMod"] = "A";
       newRow2["SysRowID"] = Guid.NewGuid();
       newRow2["RowIdent"] = newRow2["SysRowID"].ToString();
       ds.Tables["Results"].Rows.Add(newRow2);

       adapterDynamicQuery.Update(BAQName, ds);
       
       // Get Results if we need to read for example a Success or Failure Column
       // results.Tables["Results"].Rows[0]["Calculated_SomeSuccessColumn"]
       DataSet results = adapterDynamicQuery.QueryResults;

       // Cleanup Adapter Reference
       adapterDynamicQuery.Dispose();

       return results;
}

PS: For those always saying I want to log to a shared text-file on my on-prem here you go make a UBAQ and safely write in a controlled manner (dont let the User pick a path) to a UNC Path as a Service Account, Logs Away!

2 Likes