additionalScope not working!

Hello,

I am trying to trigger a query (called find_similar_parts_from_lot) to filter the table assets in a Postgres DB by 3 fields. Here is the query:

select * from assets
where asset_type = {{asset_type_id_to_match}}
and base_part_num = {{base_part_num_id_to_match}}
and orig_lot = {{orig_lot_id_to_match}};

Here is my function (defined globally) to trigger the query:

async function get_similar_assets (similar_assets_query, target_asset_type_id, target_base_pn_id, target_orig_lot_id) {
  return Promise.resolve(similar_assets_query.trigger({
      additionalScope: {
        asset_type_id_to_match: target_asset_type_id,
        base_part_num_id_to_match: target_base_pn_id,
        orig_lot_id_to_match: target_orig_lot_id
      },
    })).then((data) => data.number_in_lot);
}

I call this function from the console to test it as follows:

get_similar_assets (find_similar_parts_from_lot, "829b63a3-e5f4-4daf-ad6b-ee287c7d2e7f", "d6dde309-49f8-469a-b736-6a60d07a5017", null)

When I call the function, it does trigger the query, but does not pass in the additional scope variables, and I get an empty result (just the column names). After the function call, when I look at the query in the state viewer, its query field is:

select * from assets where asset_type = and base_part_num = and orig_lot =

So it looks like empty strings got passed in instead of my arguments. What am I doing wrong here?

Hey @sshersh!

That's actually expected for the query field if you're using additionalScope. One thing you might check is your debug tools to see what additional scope the query was triggered with:

I'm curious about the behavior of null in the query. If you want to check for an empty column I'd expect you'd need column IS NULL as opposed to column = {{ null }}. Or, alternatively, if passing null should indicate that you don't check against that column you might want to use a pattern like the one mentioned here.

Hi Kabirdas,

Turns out the null behavior was the issue. Thanks!