How to add parameters in BAQ called from a BPM

Continuing the discussion from How to read BAQ results in a BPM?:

Hello everyone, I have followed the example mentioned in the referenced post, the BAQ that I need to call needs to receive parameters, when I try to add the parameters by code, the function is not taking said parameters and therefore does not return anything, try to configure the parameters of the BPM so that in case the value is not filled, I ignore it and follow your query, then it returns what I need.

How do I add parameters to the BAQ through code?

I have tried it in the following way

But either it returns many records or nothing, with the parameters it returns a single record

1 Like

Hola pedro.

Talvez este código le funcioné, con él llame a un BAQ que tenía parámetros.

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

if (tQuery != null)
{
    Ice.Tablesets.DynamicQueryTableset dsQuery = tQuery.GetByID("BAQ");
    if (dsQuery != null)
    {
        Ice.Tablesets.QueryExecutionTableset dsBAQ = tQuery.GetQueryExecutionParameters(dsQuery); 
        
        dsBAQ.ExecutionParameter[0].ParameterID = "NombreParametro1";
        dsBAQ.ExecutionParameter[0].IsEmpty = false;
        dsBAQ.ExecutionParameter[0].ParameterValue = "ValorParametro";
        
        dsBAQ.ExecutionParameter[1].ParameterID = "NombreParametro2";
        dsBAQ.ExecutionParameter[1].IsEmpty = false;
        dsBAQ.ExecutionParameter[1].ParameterValue = "ValorParametro";

        dsBAQ.ExecutionParameter[2].ParameterID = "NombreParametro3";
        dsBAQ.ExecutionParameter[2].IsEmpty = false;
        dsBAQ.ExecutionParameter[2].ParameterValue = "ValorParametro";
        
        DataSet result = tQuery.Execute(dsQuery, dsBAQ);
        
        dsBAQ = null;
    }
    dsQuery = null;
    tQuery.Dispose();
}

You filled dsBAQ with the “Empty” parameters when you called:
tQuery.GetExecutionParameters(dsQuery)

And then you tried to add those same parameters as new ones to dsBAQ.

If you get them first, (GetExecutionParameters) you need to set them, not add them.
dsBAQ.ExecutionParameter.Where(x => x.ParameterID == "PartNum").FirstOrDefault().ParameterValue = oPartNum;

Or like Nacho :wink: (@Ignacio ) said: dsBAQ.ExecutionParameter[0].ParameterValue = oPartNum if you know the order.

If you want to add them yourself, you can do that on a new, empty dataset, or you can call Clear()
on dsBAQ.ExecutionParameter before adding them.

1 Like

Gracias, me ha funcionado.

1 Like