Need to extract a part of the parameter value

I am getting a parameter as below from the Woocommerce trigger:
“phone”:"+917003705584"

I want to have the following logic in place:
If “phone” starts with +91, then “phone” = “7003705584”

Here’s a Loom video explaining the above more clearly:

Please have a look at this:

Workflow
{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [ \n  {\n    \"json\": {\n      \"phone\": \"+917003705584\"\n    }\n  }, \n  {\n    \"json\": {\n      \"phone\": \"+517003705584\"\n    }\n  }\n] "
      },
      "name": "Make data1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -2920,
        1440
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "phone",
              "value": "={{$json[\"phone\"].startsWith(\"+91\") ? $json[\"phone\"].slice(3) : $json[\"phone\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        -2700,
        1440
      ]
    }
  ],
  "connections": {
    "Make data1": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

What I do is checking via startWith() function if phone is starting with "+91" if then slice (remove first 3 chars) otherwise return without changes.

Let me know if I can help more : )

1 Like

Hi @Shirobachi
thanks so much for your reply.
i tried it but im getting stuck at a point.
have described the issue in this video: Loom | Free Screen & Video Recording Software
can you pls help me out?
thanks!

So I see that it may be problem with catch variable, please have a look here it’s totally different case, but I showed there how to get variable by clicking.

Since I have not your workflow, I can be wrong, but I would say that adding () b/w variable could help

Hi @Shirobachi this helped ! thank you so much