Facing issues in Mapping data to a parameter

Hi I am getting data from one node and I want to map it into the next node.

  • 1st, Please check the screenshot which shows how the data is coming.
  • I am looking to map a particular field within the ‘meta_data’ field (or is it an object?)
  • Now I am giving below the json structure of the ‘meta_data’ object (at the bottom of this message)
  • In this json i need to map ‘tracking_provider’ under the key ‘_wc_shipment_tracking_items’
  • to map it, I am using the following term in the next node: {{$node[“WooCommerce Trigger”].json[“meta_data”][16][“value”][0][“tracking_provider”]}}
  • But the problem is that, sometimes, the ‘_wc_shipment_tracking_items’ key comes as the 16th item, sometimes as the 15th, sometimes as 14th and so on
  • is there a way to do the mapping such that its not dependent on the position of ‘_wc_shipment_tracking_items’ in the meta_data json?
"meta_data": [

{

"id": 221692,

"key": "mailchimp_woocommerce_campaign_id",

"value": ""

},

{

"id": 221693,

"key": "mailchimp_woocommerce_landing_site",

"value": "https://brandberrys.in/wp-admin/admin-ajax.php"

},

{

"id": 221731,

"key": "is_vat_exempt",

"value": "no"

},

{

"id": 221732,

"key": "vcwccr_country",

"value": "IN"

},

{

"id": 221733,

"key": "_wc_facebook_for_woocommerce_order_placed",

"value": "yes"

},

{

"id": 221738,

"key": "_wcpdf_invoice_settings",

"value": {

"display_shipping_address": "",

"display_customer_notes": "1",

"display_date": "invoice_date",

"display_number": "invoice_number",

"header_logo": "4081",

"header_logo_height": "",

"shop_name": {

"default": "BrandBerrys"

},

"shop_address": {

"default": "A905, Logix City centre mall , sector 32, Noida, Gautam Buddha Nagar, Uttar Pradesh - 201304"

},

"footer": {

"default": "Www.BrandBerrys.In Gst : 09AAXFB0189N1ZL"

},

"extra_1": {

"default": ""

},

"extra_2": {

"default": ""

},

"extra_3": {

"default": ""

}

}

},

{

"id": 221739,

"key": "_wcpdf_invoice_date",

"value": "1646026337"

},

{

"id": 221740,

"key": "_wcpdf_invoice_date_formatted",

"value": "2022-02-28 05:32:17"

},

{

"id": 221741,

"key": "_wcpdf_invoice_number",

"value": "506"

},

{

"id": 221742,

"key": "_wcpdf_invoice_number_data",

"value": {

"number": 506,

"formatted_number": "506",

"prefix": "",

"suffix": "",

"document_type": "invoice",

"order_id": 12156,

"padding": ""

}

},

{

"id": 221743,

"key": "_new_order_email_sent",

"value": "true"

},

{

"id": 221744,

"key": "_wishlist_analytics_processed",

"value": "1"

},

{

"id": 221746,

"key": "_ga_tracked",

"value": "1"

},

{

"id": 221747,

"key": "_wc_facebook_for_woocommerce_purchase_tracked",

"value": "yes"

},

{

"id": 221749,

"key": "ced_rnx_new_refund_line_items",

"value": {

"1550": [

]

}

},

{

"id": 221853,

"key": "_wc_shipment_tracking_items",

"value": [

{

"tracking_provider": "delhivery",

"custom_tracking_provider": "",

"custom_tracking_link": "",

"tracking_number": "12734110002741",

"tracking_product_code": "",

"date_shipped": "1646006400",

"products_list": "",

"status_shipped": "1",

"tracking_id": "01d74de6bb14321f0c68effa1c5bbbd9"

}

]

}

1 Like

Hi @Saandhy_Ganeriwala1

Please, share your code snippet/output in preformatted blocks

image

“meta_data”: [

{

“id”: 221692,

“key”: “mailchimp_woocommerce_campaign_id”,

“value”: “”

},

{

“id”: 221693,

“key”: “mailchimp_woocommerce_landing_site”,

“value”: “https://brandberrys.in/wp-admin/admin-ajax.php”

},

{

“id”: 221731,

“key”: “is_vat_exempt”,

“value”: “no”

},

{

“id”: 221732,

“key”: “vcwccr_country”,

“value”: “IN”

},

{

“id”: 221733,

“key”: “_wc_facebook_for_woocommerce_order_placed”,

“value”: “yes”

},

{

“id”: 221738,

“key”: “_wcpdf_invoice_settings”,

“value”: {

“display_shipping_address”: “”,

“display_customer_notes”: “1”,

“display_date”: “invoice_date”,

“display_number”: “invoice_number”,

“header_logo”: “4081”,

“header_logo_height”: “”,

“shop_name”: {

“default”: “BrandBerrys”

},

“shop_address”: {

“default”: “A905, Logix City centre mall , sector 32, Noida, Gautam Buddha Nagar, Uttar Pradesh - 201304”

},

“footer”: {

“default”: “Www.BrandBerrys.In Gst : 09AAXFB0189N1ZL”

},

“extra_1”: {

“default”: “”

},

“extra_2”: {

“default”: “”

},

“extra_3”: {

“default”: “”

}

}

},

{

“id”: 221739,

“key”: “_wcpdf_invoice_date”,

“value”: “1646026337”

},

{

“id”: 221740,

“key”: “_wcpdf_invoice_date_formatted”,

“value”: “2022-02-28 05:32:17”

},

{

“id”: 221741,

“key”: “_wcpdf_invoice_number”,

“value”: “506”

},

{

“id”: 221742,

“key”: “_wcpdf_invoice_number_data”,

“value”: {

“number”: 506,

“formatted_number”: “506”,

“prefix”: “”,

“suffix”: “”,

“document_type”: “invoice”,

“order_id”: 12156,

“padding”: “”

}

},

{

“id”: 221743,

“key”: “_new_order_email_sent”,

“value”: “true”

},

{

“id”: 221744,

“key”: “_wishlist_analytics_processed”,

“value”: “1”

},

{

“id”: 221746,

“key”: “_ga_tracked”,

“value”: “1”

},

{

“id”: 221747,

“key”: “_wc_facebook_for_woocommerce_purchase_tracked”,

“value”: “yes”

},

{

“id”: 221749,

“key”: “ced_rnx_new_refund_line_items”,

“value”: {

“1550”: [

]

}

},

{

“id”: 221853,

“key”: “_wc_shipment_tracking_items”,

“value”: [

{

“tracking_provider”: “delhivery”,

“custom_tracking_provider”: “”,

“custom_tracking_link”: “”,

“tracking_number”: “12734110002741”,

“tracking_product_code”: “”,

“date_shipped”: “1646006400”,

“products_list”: “”,

“status_shipped”: “1”,

“tracking_id”: “01d74de6bb14321f0c68effa1c5bbbd9”

}

]

}
1 Like

Thanks

You can use this Code in Function Node to Get all the data that is under __wc_shipment_tracking_items (We are using Regex)

Then, We are selecting the value of tracking_provider

let myArray = $node["WooCommerce Trigger"].json["meta_data"];
for (const data of myArray) {
  if(data.key.match(/_wc_shipment_tracking_items/)){
    items[0].json["tracking_provider"] = data.value[0]["tracking_provider"];
  }
}
return items;

Output:

image

Edit:

Updated the Snippet @Saandhy_Ganeriwala1

1 Like

@mcnaveen thank you so much for helping out! this worked :smiley:

2 Likes

Awesome. Enjoy :tada: