BPM Dynamic Query use

You can access any company from a BPM

1 Like

OK. I’ll give that a go …

Hmmm… I must be doing something wrong. I’ve gone through some tests and established that I can’t make a query that accesses the other company

This is about as simple a query as you can make it just to see whether it can get to the other company - it can’t

Did you check this box? (We are only one company so I’m not sure that’s the solution)

Yes, the BAQ is cross company and works a treat when it is run from the BAQ form but I want to run it from within a BPM:
When a user changes a PO line (specifically either changes the Qty or the due date). The BPM needs to check the “Linked” Job in the other company to see whether it has been released etc and then stop the changes from happening in that scenario. I’ve written the Intercompany BAQ so that it finds POs where the changes are allowable. Now I want to call that BAQ from within the BPM and see whether the results include the PO/Line which is about to be modified. I could also put Parameters on the BAQ for PO and Line and see whether the BAQ returns anything at all to the BPM. But I don’t know how to do either.

I’m not sure what’s going on with the multi company thing, I can’t really test anything since I’m a single company.

But, here is how I call a BAQ from a BPM on a C# code block. This one has parameters in it, so you should be able to see how to do that for yours.

3 Likes

Does the user running the BAQ (not you) have access to that company under Company Maintenance? If there’s security on the BAQ, does the user have access?

Yes they do but I can’t get it running under my log in anyway. I’m sure I’m missing something but I don’t know what …

OK I tried that but I’m getting a syntax error:
2019-05-21%2010_05_23-Enter%20Custom%20Code
MyPONum and MyPOLine are integer variables in the BPM and JobNum is a string variable in the BPM

It’s ExecutionParameter, not ExecuteParameter

Also, in BPm you can use Ctrl+space to get some auto-complete going for you. That will help with this type of coding.

Thanks - I just saw my typo as well…

Hey - It works :smiley:
Thanks so much for the code Brandon - Still don’t full understand it but it is getting what I need!

2 Likes

I am trying to follow your code and the other posts on here to use a BAQ within a BPM. Do you have anything in the “Usings & References” area?

I keep getting this error:

Found out. For anyone else looking for this, it’s in the screenshot below. I kept not being patient enough for the full list to load after clicking add.

5 Likes

Yeah it loads those assemblies super slow. It’s always fun waiting for the list to populate!

Curse that list! Be gone with it! @Bart_Elia
8ac619720c5a59982e938b434e6311b3

Thank you for sharing your example code. I have a similar project. I tried your code it works great. However, I can’t get the parameter to work. I am passing a value to the correct parameterID for a calculated field for my BAQ. The dynamic query always returns all rows instead of the filtered rows.

Does the parameter filter correctly when you just use the BAQ?

Yes, the following is what I am using in the data directive BPM?

using (var dq = 
Ice.Assemblies.ServiceRenderer.GetService<DynamicQuerySvcContract>(Db))
{

	// Specifiy BAQ input parameter name "LastActivity" is calculated field column name.

	var BAQname = dq.GetQueryExecutionParametersByID("MGATaskListCriticalAlert");
//																									MGATaskListCriticalAlert
  var paramLastActivity = BAQname.ExecutionParameter.Where(r=>r.ParameterID=="LastActivity").FirstOrDefault();
                                                                             
  //var paramLastActivity = BAQname.ExecutionParameter.Where (r=>r.ParameterID=="LastActivity");
	// Declare value for the input parameter LastActivity
	
  BAQname.ExecutionParameter.Clear();
	paramLastActivity.ParameterValue = Convert.ToString("-62");

	// Declare data set for the returning rows and execute the query
  var ds = dq.ExecuteByID("MGATaskListCriticalAlert",BAQname);



  // C# BLOCK must be synchronous. to work with the send email block asynchronous.  		
  callContextBpmData.Character01 =  Convert.ToString(ds.Tables["Results"].Rows[10]["Task_Key1"]);

  // 

}

The code example shared in the following post worked,
Execute Dynamic Query within BPM Data Directive - #6 by asmar