Can Conditional Inline Statements Be Used to Filter Discord Channel Names?

This topic was automatically generated from Slack. You can find the original thread here.

hi guys, is it possible to use conditions in an inline statement?
for example, I have a list of discord channels from the step:
{{steps.list_channels.$return_value}}
it contains a list of object, every object has a field “name”, I want to filter that list to only find a certain element that has a certain name.

for example, I want to find an object with a name “test-777”. I have 777 as a part of a trigger request, how can I use it to filter out the results?

something like this:
{{steps.list_channels.$return_value.where(x=>x.name.equals(“test-” + steps.body.mypersonalfield))}}

Hi , you can use any Node.js code that evaluate to string in your custom expression. It your case, it might be

{{steps.list_channels.$return_value.filter(x => x.name === `test-${steps.body.mypersonalfield}`)}}

If you’re not familiar with Node.js, I would suggest:

  1. Read more about Pipedream Node.js document here
  2. Read more about Javascript, especially Node.js part. Also you can watch through Pipedream speedrun series to have more references

nice!

I’ve updated the example, from map to filter

will it return a single object?

I need to call a field “id” from the filtered single result

it worked with …[0].id

thanks!