Describe the problem/error/question
Hey everyone, I have a question. My goal is to send a comment URL that looks like this: “{$json.body.payload.url}#note-[comment number]”. The result should look like this: “http://192.168.32.223/issues/2492#note-1”. I want the number to keep incrementing every time the function is called.
Here is my code:
// Initialize the counter variable
let counter = $('Edit Fields').item.json.number || 0;
// Define the function to process the input
function processInput(input) {
// Increment the counter for the next iteration
counter++;
// Extract notes from the input JSON
const regex = /@(\w+)/g;
const match = input.match(regex);
// Construct the new URL with the incremented counter
const newURL = `${$json.body.payload.url}#note-${counter}`;
// Remove special characters from the input value
const cleanedInput = input.replace(/[\u007F-\uFFFF]/g, '');
// Return a single object representing the output item with formatted line breaks
return {
input: cleanedInput.replace(/\r\n/g, '\\r\\n'),
match: match ? match.map(m => m.replace(/^"(.*)"$/, '$1')) : [],
newURL: newURL
};
}
// Call the function with the input
const result = processInput($json.body.payload.journal?.notes || '');
// Return the result
return result;
This code initializes a counter variable, increments it each time the function is called, and constructs a new URL with the incremented counter. It also extracts notes from the input JSON, removes special characters from the input value, and returns a single object representing the output item with formatted line breaks.
What is the error message (if any)?
Please share your workflow
Share the output returned by the last node
Information on your n8n setup
- n8n version: 1.35.0
- Database (default: SQLite):default
- n8n EXECUTIONS_PROCESS setting (default: own, main):default
- Running n8n via (Docker, npm, n8n cloud, desktop app):Docker
- Operating system:Linux