BAQ in BPM Code Block

I can’t seem get this working, I’ve tried it a dozen different ways. I’ve done my homework, read a ton of related posts and not sure what I’m doing wrong. I’m trying to fire a BAQ, in a BPM code block, that grabs specific job information but it seems to be failing to get any results with “No Rows Returned!”. Hoping someone could help me understand what I’m doing wrong. This is a post-processing method directive, “QuickJobEntry.GenerateJob”

Ice.Contracts.DynamicQuerySvcContract tQuery = Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.DynamicQuerySvcContract>(Db);

if (tQuery != null)
{

this.PublishInfoMessage("tQuery not null" + "\n" + Job.ToString(), Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");

Ice.Tablesets.QueryExecutionTableset dsQueryExecution = new QueryExecutionTableset();

ExecutionParameterRow drRow = new ExecutionParameterRow();

drRow.ParameterID = "JobNum"; // name of parameter from BAQ
drRow.ParameterValue = Job.ToString();
drRow.ValueType = "nvarchar";
drRow.IsEmpty = false;
drRow.SysRowID = Guid.NewGuid();
drRow.RowMod = "A";
dsQueryExecution.ExecutionParameter.Add(drRow);


DataSet results = tQuery.ExecuteByID("QuickJobAutoPO", dsQueryExecution);

if (results.Tables["Results"].Rows.Count == 0)
  {
    
    this.PublishInfoMessage("No Rows Returned!", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
      
  }
  else
  {

     this.PublishInfoMessage("Rows Returned!", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
  }
}

Thank you!

edit;
A word

Can you confirm that this is returning a value with a MessageBox?
Also, have you tried running the the BAQ manually with a specific Job?

1 Like

Ditto what cfinley said… but also, do you really want that type of dependency, you could query it in a BPM via LINQ and eliminate a BAQ dependency. Code looks okay.

1 Like

Yes, it does return a value. The BAQ works perfectly when ran manually, only returning one line.

Is your BAQ Shared and set for All Companies?

I would agree with hasokeric on potentially eliminating the dependency. Not sure when you upgrade if this BAQ would be caught anywhere as being “used”.

Regardless.

Is the BAQ in the same company?

Not that this is correct, but I recently had some troubles with calling BAQ from a customization. Only differences between my customization and my playground/test area was potentially my isEmpty parameters and my RowMod which I left “”.

It was something I didn’t get time to play around with. But perhaps what you are experiencing as well?

Also, never dived into exploring this. But are BPMs async in any nature? if so perhaps your BAQ is not returning a value before the BPM checks for results

The only difference I have in my BPM that calls a BAQ is

SysRowID = Guid.Empty

Unfortunately I’m not a programmer by nature and struggle with LINQ queries, otherwise I would do this in a heartbeat.

If you would be so kind as to give an example, using job number from ttQuickJob to pull data from JobProd table with 2 criteria; subcontract = true and and VendorNum = 497, this might eliminate my need for the BAQ.

From my understanding, it would be something like:

JobProd = (var JobProd_iterator in (from JobProd_Row in Db.JobProd
where JobProd_Row.JobNum == ttQuickJobRow.JobNum
&& JobProd_Row.Subcontract == true
&& JobProd_Row.VendorNum == 497
select JobProd_Row))
var Rows = 
	(from jp in Db.JobProd 
		where jp.Company == Session.CompanyID 
			 && jp.VendorNum == 497
		select jp
	).ToList(); // You can also use .FirstOrDefault() if you only want 1 row

Just for example sake, a JOIN example:

var Rows = 
	(from jh in Db.JobHead 
	
		join jp in Db.JobProd.With(LockHint.NoLock)
			on new { jb.Company, jh.JobNum, Subcontract = true } equals new { jp.Company, jp.JobNum, jp.Subcontract }
			
		where jh.Company == Session.CompanyID 
			 && jp.VendorNum == 497
			 
		select jp
	).ToList();
2 Likes

@CasterConcepts, Can you show us your BAQ (screenshot of query builder is fine) and let us know the business objective?

I think this is more of a data structure issue than a code syntax problem… For starters, JobProd does not have “Subcontract” and “VendorNum” fields…

@TomAlexander, I’m sorry, I said JobProd but I meant JobOper.

The objective is to only find subcontract operations, the vendor being one of our other companies, there will only be 1 of these ops per job and not all jobs have this operation.

image

image

image

image

I envy your skills sir… I did use FirstOrDefault, as I only want the 1 line. Can’t believe it was that easy… I need to learn more about Linq…

Final results was literally:

var JobOper = 
  (from jo in Db.JobOper 
    where jo.Company == Session.CompanyID
       && jo.JobNum == Job
       && jo.SubContract == true
       && jo.VendorNum == 497
    select jo
  ).FirstOrDefault();
  
  Asm = JobOper.AssemblySeq;
  Opr = JobOper.OprSeq;

The only rule of thumb is to make sure you check that you actually found a record.

if (JobOper != null) {
  Asm = JobOper.AssemblySeq;
  Opr = JobOper.OprSeq;
}

Second is don’t do a SELECT * if you don’t have to:

var JobOper = 
  (from jo in Db.JobOper 
    where jo.Company == Session.CompanyID
       && jo.JobNum == Job
       && jo.SubContract == true
       && jo.VendorNum == 497
    // Select only what you need for faster query
    select new {
       jo.Company,
       jo.AssemblySeq,
       jo.OprSeq
    }
  ).FirstOrDefault();
1 Like