The bottom line is that I need to first check the incoming data with what is already in the table. if no match is found, add the data (as new) to the next lines.
I try this way.
function onEdit(event) { var content = JSON.parse(event.postData.contents); var ss = event.source.getActiveSheet(); var r = event.source.getActiveRange(); if(r.getColumn() == 2){ //column B if(r.getValue() == content['order'].order_number) { var id = ss.getRange('B'+r.getRow()).getValue(); // order id from the column A ss.getRange('V'+r.getRow()).setValue(content['order'].status+' Время обновления статуса '+new Date()); } else{ row.push(new Date()); row.push(content['order'].order_number) row.push(content['order'].shipping_address.first_name+' '+content['order'].shipping_address.last_name) row.push(content['order'].billing_address.email) row.push(content['order'].total_line_items_quantity); var item = ""; for (var i=0;content['order'].line_items.length>i;i++){ item=item+content['order'].line_items[i].quantity+' -'+content['order'].line_items[i].name+','; } item=item.substring(0,item.length-1); row.push(item); row.push(content['order'].total) row.push(content['order'].payment_details.paid) row.push(content['order'].status) row.push(content['order'].payment_details.method_title) row.push(content['order'].shipping_address.address_1+','+content['order'].shipping_address.city+','+content['order'].shipping_address.country+','+content['order'].billing_address.phone+', ZIP:'+content['order'].billing_address.postcode) row.push(content['order'].shipping_methods) row.push(content['order'].note) row.push(content['order'].view_order_url) var ss = SpreadsheetApp.openById('sheet id') var sheet = ss.getSheetByName("Sheet1"); sheet.appendRow(row); result.result = 'ok'; } } }
If you simply add data to the table (everything in the code after the else), it works, and if it doesn’t work with the search :( Tell me how to combine the two functions in one macro (Search / Replace - and add this if there are no matches ).
onEdit
question, and in the answerdoPost
? What is a "macro"? In Google Apps Script, programs are called "scripts." Give a simpler example. Preferably with a table. - oshliaer pm