How-To Zero Pad field with Edit Fields node

Describe the problem/error/question

I want to zero pad a string from “123456” to “0000123456”. Tried using the Edit Fields node with this code: {{ $json.receiver_site_name.padStart(10,‘0’) }}

What is the error message (if any)?

Problem in node ‘Edit Fields1‘
The include option “202436” is not known!

Please share your workflow

“meta”: {
“instanceId”: “1db75c6230f902c1e4a8140be9c37e616aa2a4fdcfa14994f717a5ea355cc9bd”
“nodes”: [
“parameters”: {
“fields”: {
“values”: [
“name”: “receiver_site_name”,
“stringValue”: “={{ $json.receiver_site_name.padStart(10,‘0’) }}”
“include”: “={{ $json.receiver_site_name }}”,
“options”: {}
“id”: “35bc9e7b-4697-4966-82a9-f0429a7e7cd3”,
“name”: “Edit Fields1”,
“type”: “n8n-nodes-base.set”,
“typeVersion”: 3.2,
“position”: [
“connections”: {},
“pinData”: {}

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

Try adding .toString() before any other methods.
So it will be {{ $json.receiver_site_name.toString().padStart(10,‘0’) }}

padStart() is a String method so it won’t work on number types.

i don’t think it’s possible to have leading 0s in a number type in JS, which is why it needs to be converted to string.

If that doesn’t work try it in a code node, that will give you a better error message to share

1 Like

I was thinking it was a number but was represented as a string in the CSV file I’m importing. I will try that code to see if it will work for me.