Error in _.include() syntax?

Hello again!
Does anyone have any idea why the following code is not working in our custom table column to check whether the sample has been invoiced or not?

{{ _.includes(getInvoicedItemsIMRID.data, currentSourceRow.imr_id) }}

It seems from the JS syntax that it should be OK, but all rows are returning false, even though some of them, such as the second highlighted row in the below screenshot, have imr_ids that are present in the array returned from the getInvoicedItemsIMRID query.

HI there,

Not sure why it isn't working as I'm not familiar with the lodash include function. However, I would suggest using:

{{ getInvoicedItemsIMRID.data.some(item => item.imr_id === currentSourceRow.imr_id) }}

It also depends on how your IMRID data is structured.

Thanks for the suggestion - what you are actually saying to use is an alternative lodash function (_.some()), and I could have structured the JS using the _.includes in the same way (ie: getInvoicedItemsIMRID.data.includes...), however when I try both yours above + the inlcudes version, I always get the Retool function error:

TypeError: getInvoicedItemsIMRID.data.some is not a function

...so I thought I could not use the "function" structure and instead have to use the standard "declared" version of using lodash (such as {{ _.includes(...) }} ).

The IMRID data is coming from the query call on the bottom of the screenshot (with the data output on the bottom right) and presents itself as an array of values which .includes is supposed to be able to handle (.some also).

Hi @dr.andre,

I'm actually not suggesting to use lodash at all.

However, I think I know what the problem is in both scenarios, your data is not structured as an array in the format that retool wants it. You can try either:

  1. add formatDataAsArray (data) to your query transformer
  2. add it within this javascript lines we are discussing

Thanks again!
What I meant earlier was simply that your .some suggestion was a lodash function as well (like .includes) - they are lodash and end up being interpreted in the background of Retool as the "add-on" functions when you use the X.some notation: Lodash _.some() Method - GeeksforGeeks

The data coming from the query was already formatted as an array, but your above comment had me poking around the array and so I found the error - it was just a very small syntax problem about specifically saying which part of the array to search (even though the query only returns one set of values in the array):

{{ _.includes(getInvoicedItemsIMRID.data.imr_id, currentSourceRow.imr_id) }}

...so the only difference there is getInvoicedItemsIMRID.data.imr_id vs. getInvoicedItemsIMRID.data.

2 Likes