Do somethink when a Gmail Label exists

Hi all. I’m writing a workflow where I need to check if an email (unread) has a label and if there isn’t I need to add this label and send an email.
I have no problem to get new email, get the list of the current email’s labels, loop through the lists of labels to check if the label is present, but I don’t know how to
follow a flow when the label is not present in the email’s labels. I can not use “variables” because I’m on the free plan.
And I don’t want use Javascript.

Any possibility ?

thanks

M.

Information on your n8n setup

  • n8n version: last online
  • Database (default: SQLite): online
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud
  • Operating system: n8n cloud

That’s absolutely possible in n8n.
You could employ either If or Switch node to handle the case.
Care to share your workflow with some data pinned?

Hi, it’s possible if I edit my array via JS before the IF node, where JS transform (for example) my array in a string like “n8n imporant mylabel2”. But I don’t want to use JS because many pleople don’t know this programming language.

However thanks.

M.

I’m not quite sure if I follow you. Was it a statement or a question?

n8n offers quite a number of nodes for data extraction and transformation where you do not need any JS at all.

You must have a broader picture and context in your head that doesn’t manifest in this topic.

I have this situation:

I need to check if “labels” array contains an item where “name” is equal “n8n”.
I don’t know how to continue after the “loop” node only if there isn’t an item with name “n8n”. I can use javascript ($input…map(…)) in a “code” node but I don’t want use JS.

Thanks.

Please help to help you.

Sorry to interrupt you.

I have the very similar issue.

Main idea is the same:
0.I’m a lawyer and i receive lots of messages from courts about my cases; all of them have the same schema and can be categorized.

  1. receive a message.
  2. check if it complies with the rule:
    the message body should contain specific value over the pattern - like 922/194/23
    3 digits, separator “/”, 1 to 5 digits, separator “/”, 2 digits.
  3. if it complies - get all existing labels from mailbox.
  4. chech if there existing a label, that matches pattern above.
  5. if yes - set this existing label to new message.
  6. if no - create new label with the pattern, then set this new label to new message which body contains that specific pattern

I’m stuck on steps 5 and 6.

Will appreciate your advice.

  • n8n version: 1.85.4
  • Database (default: SQLite): postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Docker

Hi, via CODE node you can do it via JS.

function estraiPattern(body) {
  const pattern = /\b\d{3}\/\d{3}\/\d{2}\b/;
  const match = body.match(pattern);
  return match ? match[0] : null;
}

// Esempio d'uso:
const body = "C'è un codice interessante: 922/194/23 in questo testo.";
const risultato = estraiPattern(body);

return {"pattern": risultato} 

the node’s output will be a JSON/SCHEMA like {“pattern”: “922/194/23”} or {“pattern”: “”} (the last if 922/194/23 is not contained in the body).

M.

1 Like

Thank for your reply.
I have no problem to find the messages, which comply with the pattern.
The problem is to

  1. set exeisting labels depending on the pattern
    [IF message comply with pattern AND label, which comply with pattern exist, THEN set to this message label]
    add
  2. add new labels and set them to messages
    [IF IF message comply with pattern AND thehe is no label, which comply with pattern exist, THEN
    label with the pattern AND set this new label to this message].

That is the problem (

AH ok… A thing like this one

Thank for your replies.
I’ve received the purpose i was looking for.

Here is the full working workflow.

A week past, and I got a new problem.
Please advice how to improve the workflow.

The problem is that workflow only works for one item only.

Here is settings for “Message received” node

So there are situation, when 5 messages are received in one time.
Workflow only proceeds one of them and stops.

I tried to change modes of the Code nodes to Run Once for each Item, but it didn’t change anything.

I understand, that i should use Loop Over Items node somewhere, but, honestly, I didn’t get its logic, even after watchig YouTube videos.

Appreciate your advice.

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