将三张工作表中的订单数据自动合并到一个Google工作表中并同步新记录。

huangapple go评论57阅读模式
英文:

How To Automate Combining Orders Data From 3 Worksheets Into A Single Google Worksheet & Sync Over New Records

问题

合并工作表中的数据到主订单表格

大家好,
我们使用Google表格来跟踪我们的在线订单,将每个市场的订单存储在同一工作簿内的各自工作表中。目前,我们有3个工作表:ebay、etsy和amazon。有外部脚本在整天运行,随着订单的到来,将记录插入到各自的工作表中。

我们手动将订单记录转移到名为“GI Orders”的单一主工作表中。从那里,我们有一个内部工作流程,其中我们为每个订单设置“作业”,在电子表格中记录给定订单的作业编号,并在处理后标记为已完成。

这些手动输入仅在主GI Orders工作表上完成,每条记录都记录在A:C列中,从D列开始是数据。

复制记录很容易,因为所有工作表都具有相同的列。困难之处在于找出哪些订单已经复制到主表中,哪些是新的(在最后一次复制/粘贴操作之后插入的)。我也不知道如何以编程方式存储/处理哪些记录已经复制,因此可以在下一次脚本执行期间跳过它们。

我们的目标

  • 自动化将3个数据源工作表中的数据手动转移到主GI Orders工作表中。
  • 每当任何数据源工作表中添加新行或以固定间隔(例如,每小时)复制新记录(增量),将它们添加到底部以不覆盖任何现有记录。

非常感谢您的所有帮助!

表格链接

英文:

Combine Data from Worksheets Into A Master Orders Sheet

Hi all,
We use a Google Sheet to track our online orders, storing the orders from each marketplace in their own sheet within the same workbook. Currently, we have 3 worksheets: ebay, etsy and amazon. There are external scripts that run throughout the day inserting records into each respective worksheet as the orders come in.

We manually transfer the the order records into a single master worksheet called "GI Orders". From there, we have an internal workflow that occurs in which We setup "jobs" for each order, record the job number(s) for a given order in the spreadsheet, and mark it as done, once processed.

These manual inputs are ONY done on the master GI Orders worksheet, per record, and are recorded in columns A:C, everything from Col D is just data.

Copying records easy because all the sheets have identical columns. The difficulty is in figuring out which orders were already copied over to the master vs which ones are new (inserted after the last copy/paste operation). I also do not know how to programmatically store/handle which records were already copied, and thus can be skipped over during the next script execution.

Our Goal

  • Automate the manual transfer of data from the 3 data feed worksheets into the master GI Orders worksheet.
  • Repeat the process automatically whenever new rows are added into any of the feed sheets, or copy over new records (delta) at regular intervals (e.g., hourly), adding them to the bottom of sheet so as to not overwrite any existing records.

Many, many thanks in advance for all your assistance!

Link To Sheet

答案1

得分: 0

你有三张包含订单信息的外部表格。外部表格中的数据被导入到主表格中的三张独立表格中。

随着新订单的导入,你希望从每个“导入”表格中复制数据,并将其合并到第四张表格“GI订单”中。但是,你需要确保在“GI订单”上不会创建重复的条目。

如果在“GI订单”上找到“订单号”和“SKU”组合重复,就可以识别重复交易。

function updateOrders(){
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  // 创建包含此电子表格中表格名称的数组
  var source = ["ebay","etsy","amazon"]

  // 获取GI订单数据
  var giOrders = ss.getSheetByName("GI Orders")
  var giOrdersData = giOrders.getDataRange().getValues()
  
  // 获取订单号的一维数组并删除标题行
  var giorders = giOrdersData.map(function(e){return e[1]})
  giorders.splice(0,1);

  // 获取SKU的一维数组并删除标题行
  var gisku = giOrdersData.map(function(e){return e[24]})
  gisku.splice(0,1);

  // 创建数组以保存合并后的订单号/SKU
  var giArray = new Array
  for (var i=0;i<giorders.length;i++){
    var gikey = giorders[i]+gisku[i]
    giArray.push(gikey)
  }

  // 获取交易数据
  // 创建数组以保存任何非重复交易
  var cleanTrans = new Array

  // 遍历表格
  for (var s = 0;s<source.length;s++){
    var sourceSheet = ss.getSheetByName(source[s])

    // 获取交易数据
    var transData = sourceSheet.getDataRange().getValues()

    // 获取订单的一维数组并删除标题行
    var orders = transData.map(function(e){return e[0]})
    orders.splice(0,1);

    // 获取SKU的一维数组并删除标题行
    var sku = transData.map(function(e){return e[23]})
    sku.splice(0,1);

    // 遍历订单/SKU  
    for (var i=0;i<orders.length;i++){
      // 合并订单和SKU
      var key = orders[i]+sku[i]

      // 组合的订单号/SKU在GI订单中吗?
      // 如果没有匹配,indexOf返回-1
      var idx = giArray.indexOf(key);

      if (idx == -1){
        // 没有找到匹配,所以添加到GI订单
        transData[(i+1)].unshift(source[s])
        cleanTrans.push(transData[(i+1)])
      }
    }
  } // 交易循环结束

  // 如果有新的交易,则追加到GI订单
  if (cleanTrans.length > 0){
    var giLR = giOrders.getLastRow()
    giOrders.getRange(giLR+1,1,cleanTrans.length,25).setValues(cleanTrans)
  }
}
英文:

You have 3 external sheets containing order information. The data from the external sheets is imported into three separate sheets in a master spreadsheet.

As new orders are imported, you want to copy the data from each of the three "import" sheets and combine it on a fourth sheet "Gi Orders". However, you need to ensure that you don't create duplicate entries on "GI Orders".

A duplicate transaction can be identified if the combination of the "Order Number" and "SKU" are found to be duplicated on "GI Orders".


function updateOrders(){
var ss = SpreadsheetApp.getActiveSpreadsheet()
// create an array of the sheet names in this spreadsheet
var source = [&quot;ebay&quot;,&quot;etsy&quot;,&quot;amazon&quot;]
// get the GI Orders data
var giOrders = ss.getSheetByName(&quot;GI Orders&quot;)
var giOrdersData = giOrders.getDataRange().getValues()
// get a 1D array of the order nuimbers and remove the header row
var giorders = giOrdersData.map(function(e){return e[1]})
giorders.splice(0,1);
// get a 1D array of the SKU and remove the header row
var gisku = giOrdersData.map(function(e){return e[24]})
gisku.splice(0,1);
// create an array to hold the combined order#/SKU
var giArray = new Array
for (var i=0;i&lt;giorders.length;i++){
var gikey =giorders[i]+gisku[i]
// Logger.log(&quot;DDEBUG: source = GI Orders , i=&quot;+i+&quot;, order = &quot;+orders[i]+&quot;, sku = &quot;+sku[i]+&quot;, key = &quot;+key)
giArray.push(gikey)
}
// get the transaction data
// create an array to hold any non-duplicate transactions
var cleanTrans = new Array
// loop through the sheets
for (var s = 0;s&lt;source.length;s++){
var sourceSheet = ss.getSheetByName(source
展开收缩
) // get transaction data var transData = sourceSheet.getDataRange().getValues() // get a 1D array of Orders and remove the header row var orders = transData.map(function(e){return e[0]}) orders.splice(0,1); // get a 1D array of SKU and remove the header row var sku = transData.map(function(e){return e[23]}) sku.splice(0,1); // loop through the order/sku for (var i=0;i&lt;orders.length;i++){ // combine the order and sku var key = orders[i]+sku[i] // Logger.log(&quot;DEBUG: source = &quot;+source
展开收缩
+&quot;, i=&quot;+i+&quot;, order = &quot;+orders[i]+&quot;, sku = &quot;+sku[i]+&quot;, key = &quot;+key) // is the combined order#/sku in GI Orders? // indexOf returns -1 if there is no match var idx = giArray.indexOf(key); if (idx == -1){ // no match found, so add to gi Orders // Logger.log(&quot;DEBUG: no match &quot;+key+&quot; result = &quot;+idx) // add the source to the array transData[(i+1)].unshift(source
展开收缩
) cleanTrans.push(transData[(i+1)]) } else{ // do nothing // Logger.log(&quot;DEBUG: match found: &quot;+key+&quot; result = &quot;+idx) } } // Logger.log(cleanTrans) // DEBUG // Logger.log(&quot;DEBUG: source = &quot;+source
展开收缩
+&quot;, numbers of transactions = &quot;+ cleanTrans.length) } // end of transactions loop // if any new Trans, then append to giOrders if (cleanTrans.length &gt;0){ var giLR = giOrders.getLastRow() giOrders.getRange(giLR+1,1,cleanTrans.length,25).setValues(cleanTrans) } }


Sample GI Orders - BEFORE consolidation
将三张工作表中的订单数据自动合并到一个Google工作表中并同步新记录。

Sample GI Orders - AFTER consolidation
将三张工作表中的订单数据自动合并到一个Google工作表中并同步新记录。

Sample Imported Orders - eBay

将三张工作表中的订单数据自动合并到一个Google工作表中并同步新记录。

Sample Imported Orders - etsy

将三张工作表中的订单数据自动合并到一个Google工作表中并同步新记录。

Sample Imported Orders - amazon

将三张工作表中的订单数据自动合并到一个Google工作表中并同步新记录。

huangapple
  • 本文由 发表于 2023年5月21日 07:56:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297780.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定