Assigning value and logic

Describe the problem/error/question

Hi Team,

I hope you all are doing well.

I have been working on an issue, but it seems to have become a bit complicated.

Here is my use case:

  • Fetch the Brevo user email ID from brevoUser via the brevoUserEmails property.
  • Fetch the HubSpot user email ID from hubSpotUser via the hubSpotUserEmails property.
  • [ownerDetails CODE node] Once I have these email IDs from Brevo and HubSpot, I want to perform a matching operation:
    • Iterate through each email ID in hubSpotUserEmails and compare it to the email IDs in brevoUserEmails.
    • If there is a match, the email will be assigned to owner.
    • If there is no match, the email ID from brevoUserEmails with ownership set to true will be used.

Currently, I am facing an issue where retrieving the emails from brevoUser and hubSpotUser fails at the CODE node.

My expected output is to get each individual email from brevoUser (including brevoUserEmails and ownership) and hubSpotUser (hubSpotUserEmails).

Reference Issue

Case 2: if the code in the code node

const brevoAccountEmail = $("brevoUser").item.json["brevoUserEmails"];
const hubSpotAccountEmail = $("hubSpotUser").item.json["hubSpotUserEmails"];
const ownerShip = $("brevoUser").item.json["ownerShip"];

return {brevoAccountEmail, hubSpotAccountEmail, ownerShip};

My expected output from code node is

|brevoAccountEmail | hubSpotAccountEmail | ownerShip|

|— | — | —|

|[email protected] | [email protected] | true|
|[email protected] | [email protected] | false|
|[email protected] | [email protected] | false|

What is the error message (if any)?

Please share your workflow

Question 3:

  • {{ $json.properties.propertyName }}
  • {{ $(‘nodeName’).first().json.properties.propertyName }}
  • {{ $(“nodeName”).item.json[“properties”][“propertyName”] }}

How the above are different from each other, what are the other ways to get the data from one node property

Thanks in advance for your help.

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.234.1
  • Database (default: SQLite): postgresql
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: MAC

Although I am not certain and some testing could confirm it, but perhaps setting multiple inputs into the code node and setting it to run once per item, makes me logically think that it is running on each entry, and obviously one would be undefined if the other runs first.

Did your merges not work? Or perhaps try changing the input to all instead of each for the code node.

Did your merges not work?
No!!

Or perhaps try changing the input to all instead of each for the code node.
Didn’t get you!!

hello @Gouravdev

Code node won’t work with multiple inputs. You can do it by merging items together and then using the Code node logic

2 Likes

Thanks @barn4k for quick response.

I have tried many case but still I am facing some issue :frowning:

Please help here,

I want each value of hubSpotUserEmails will iterate into each value of brevoUserEmails, if it matches then matched value will be assigned to matchedEmail else assign $(“Merge”).first().json[“brevoUserEmails”]; to it and return the matchedEmail

because of undefined values I am not able to get this.

If I understand you correctly.

Why not simply (this is not exact javascript code):

if (typeof item.hubSpotEmail == "object") {
return {matchedEmail: item.hubSpotEmail}
} else if (typeof item.brevoUserEmails == "object") {
return {matchedEmail: item.brevoUserEmails}
}

This will return a single email for either if one is an object/not undefined.

Why are you trying to do so? The data from Brevo and Hubspot may be returned in a different order as well as the amount of the returned emails could be different. The one-by-one comparison won’t work in that case

I have found workaround and now it’s working fine :wink:

Thanks, @barn4k and @ThinkBot, for your response. I have found a workaround and fixed the above issue.

Could you please help with the following?

Issue 1: In the HTTP node, the Body Content Type is form-data, and the parameter type is Parameter Type. Even though I am passing the file as a body parameter, it is still showing an error.

Thanks in advance!!

Passing you a file or a link to file? If it is a file, I suggest using the n8n Binary File as the parameter type. Is it is a link, then check that the link is correct and the file is accessible

it’s a aws link and I have checked it exist. Still, getting this issue.

The issue isn’t unclear as it comes from the external service. Maybe the service expects for the file itself instead of the link?

1 Like

Thanks @barn4k :slight_smile:

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