How to add value in the existing object

 let body = {

                    “type”: “OUTBOUND”,

                    “details”: {

                        “urgent”: false,

                        “arrivaldate”: itemFulRecordSearch.orderDate,

                        “collect”: {

                            “requiredDate”: convertedOrderDate

                        },

                        “deliver”: {

                            “address”: {

                                “companyName”: itemFulRecordSearch.companyName,

                                “contactName”: itemFulRecordSearch.customer,

                                “address1”: itemFulRecordSearch.shipaddress1,

                                “city”: itemFulRecordSearch.shipcity,

                                “state”: {

                                    “code”: itemFulRecordSearch.shipstate

                                },

                                “postcode”: itemFulRecordSearch.shipzip,

                                “country”: {

                                    “iso2Code”: itemFulRecordSearch.shipcountry

                                },

                                “phone”: itemFulRecordSearch.cusPhone,

                                “email”: itemFulRecordSearch.email

                            },

                            “instructions”: itemFulRecordSearch.deliveryins,

                            “requiredDate”: convertedDeliveryDate,

                        }

                    },

                    “customer”: {

                        “id”: custId,

                        “name”: reduceValues.custName + ‘-‘ + itemFulRecordSearch.docuNo,

                        “references”: {

                            “id”: custId

                        },

                    },

                    “warehouse”: {

                        “name”: warehouseName

                    },

                    “references”: {

                        “customer”: itemFulRecordSearch.docuNo

                    },

                    “items”: items,

                };

                // Check if address2 is not empty before adding it to the address object

                if (itemFulRecordSearch.shipaddress2) {

                    body.details.deliver.address = {

                        body.details.deliver.address,

                        address2: itemFulRecordSearch.shipaddress2

                    };

                }

Leave a comment

Your email address will not be published. Required fields are marked *