Conditional statements on multiple different arrays

I would like to output only when the conditions are met in multiple arrays with different numbers, and output a different message if they are not met, but I am not sure how to do this.

For example, you need something like this:

  1. Retrieve dozens of pieces of information from specific data. This is a random quantity
  2. Obtain user information from other data.
  3. If the user name is included in the list obtained in (1), the content in (1) is included when sending a Slack DM.
  4. If the username is not in (1), just send a simple Slack DM.
  5. Ultimately, DMs equal to the number of users acquired in (2) must be sent.

The maximum I can think of is attached. However, this doesn’t work correctly.
Because it is difficult to provide exact samples, they were made as similar as possible.

Other sample data is also fine. Please advise if there is a more efficient (faster, more sophisticated) method than the above method.
I hope you understand my English is lacking.


In summary, in two arrays with different numbers
I want to find cases where the username word in B data is included in the A data list.
If found, Slack DM including the body of the A data
If you can’t find it, send Slack DM just once without body (in the example, if the if statement is false, 10 DMs are sent, which is the problem)

hi @Supka

For the simplicity, add Split in batches node instead of Item Lists node, set Split to 1 item and proceed it one by one. Don’t forget to link you workflow ending to the split node so it could be processed in a loop

hello, @barn4k

Thank you for your comment.
I’ll actually test it out.
However, in my opinion, if there is no item list(concatenateItems) to return 100 items as 1 in the beginning, wouldn’t the http request in the latter part be attempted 100 times instead of 1?

Still, it seems like it can work. I’ll try more first

If I were to implement my situation with python code, I think it would probably look like this:

import json

data1 = ["apple", "banana", "google", "test", "note"]
data2 = ["waffle", "duck", "goo"]

# Function to check if data2 is included in data1
def check_inclusion(data1, data2):
    inclusion = {}
    for item2 in data2:
        for item1 in data1:
            if item2 in item1:
                inclusion[item2] = item1
            inclusion[item2] = None  # Include the key with None value if not found in data1
    return inclusion

# Check for inclusion and construct the final dictionary
inclusion_dict = check_inclusion(data1, data2)

# Convert to JSON format
result_json = json.dumps(inclusion_dict, indent=4)

# Print the result

And its result is as follows.

     "waffle": null,
     "duck": null,
     "goo": "google"

This is the same as my purpose of sending a normal DM to an object with a null value and a DM including the body to an object with a google value.
Everything must be completed in just one session.

Of course, there are ways to use Python or JavaScript code, but I prefer non-code as much as possible.
love u n8n

I tried many things to find a way, but it was a little difficult for me as a beginner.
Finally, we realized what we wanted.
I don’t know if it’ll help, but if I share it, it’s as follows

  1. Import data periodically from a separate workflow, reprocess it into the data format I want, and save it as a file in the /tmp folder on the system
  2. Find files in local /tmp during process processing in other workflows and see if specific keywords match in them
    The values used at this time are as follows.
    grep "{{ $('Set8').item.json.real_name }}" /tmp/calendar_{{ $today.format("yyyyMMdd") }}.log || echo “Null”
  3. Workflow is then modified to ride process A if null and process B if not null
  4. I think it’s working well.
  5. (I estimate the /tmp folder will be periodically deleted with Linux default settings, and I don’t think it’ll be too much of a burden to operate only once a day.)

If you have any better ideas, please share them with each other.


1 Like

Actually, you can do a filtering with a little js (sad, but it is the easiest way). Example below. Data1 and Data2 nodes are samples for HTTP nodes. Plus you can enable Run Once property in the second HTTP node to execute the node only once (so you don’t need a Item Lists node).

So the trick here is to convert the titles part (or any other property you are interested in) of the output of the first HTTP node into string and just check if the title in the second HTTP node output is part of that long string (with indexOf() method)


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.