Skip to content

Instantly share code, notes, and snippets.

@cpuwolf
Last active January 12, 2024 06:12

Revisions

  1. cpuwolf revised this gist Jan 12, 2024. 1 changed file with 14 additions and 3 deletions.
    17 changes: 14 additions & 3 deletions AirScript.js
    Original file line number Diff line number Diff line change
    @@ -24,8 +24,8 @@ function fetchAllRecords() {
    let records = sheet.Record.GetRecords({
    ViewId: view.viewId,
    Offset: offset,
    MaxRecords: 5,
    Fields: ["状态", "日期"],
    MaxRecords: 1,
    Fields: ["编号","状态", "日期"],
    Filter: {"mode": "AND", "criteria": [{
    "field": "状态",
    "op": "Equals",
    @@ -44,4 +44,15 @@ function fetchAllRecords() {
    }

    const recs = fetchAllRecords()
    console.log(recs)
    console.log(recs)
    for(var i=0; i< recs.length; i++) {
    const upded = sheet.Record.UpdateRecords({
    Records: [{
    id: recs[i].id,
    fields: {
    "状态": "已取消",
    }
    }],
    })
    console.log(upded);
    }
  2. cpuwolf revised this gist Jan 12, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions AirScript.js
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@
    var d = new Date();
    // Set it to one month ago
    d.setMonth(d.getMonth() - 1);
    d.setDate(1)
    // Zero the time component
    d.setHours(0, 0, 0, 0);
    // Get the time value in milliseconds and convert to seconds
  3. cpuwolf revised this gist Jan 12, 2024. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions AirScript.js
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,12 @@ d.setMonth(d.getMonth() - 1);
    // Zero the time component
    d.setHours(0, 0, 0, 0);
    // Get the time value in milliseconds and convert to seconds
    console.log(d);
    datestr = d.toLocaleDateString("zh-CN")
    console.log(datestr);
    // 获取当前工作表
    const currentSheet = ActiveSheet
    console.log(Application.ActiveSheet.Name)
    Application.Sheets.Item('cccc').Activate()
    Application.Sheets.Item('国外订单自动化').Activate()
    const sheet = Application.ActiveSheet
    function fetchAllRecords() {
    const view = sheet.Selection.GetActiveView()
    @@ -24,11 +25,15 @@ function fetchAllRecords() {
    Offset: offset,
    MaxRecords: 5,
    Fields: ["状态", "日期"],
    Filter: {"criteria": [{
    Filter: {"mode": "AND", "criteria": [{
    "field": "状态",
    "op": "Equals",
    "values": ["待付款"]
    }]}
    },{
    "field": "日期",
    "op": "Less",
    "values": [datestr]
    },]}
    })
    offset = records.offset
    all = all.concat(records.records)
  4. cpuwolf created this gist Jan 12, 2024.
    41 changes: 41 additions & 0 deletions AirScript.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@

    //
    // Get a date object for the current time
    var d = new Date();
    // Set it to one month ago
    d.setMonth(d.getMonth() - 1);
    // Zero the time component
    d.setHours(0, 0, 0, 0);
    // Get the time value in milliseconds and convert to seconds
    console.log(d);
    // 获取当前工作表
    const currentSheet = ActiveSheet
    console.log(Application.ActiveSheet.Name)
    Application.Sheets.Item('cccc').Activate()
    const sheet = Application.ActiveSheet
    function fetchAllRecords() {
    const view = sheet.Selection.GetActiveView()
    let all = []
    let offset = null;

    while (all.length === 0 || offset) {
    let records = sheet.Record.GetRecords({
    ViewId: view.viewId,
    Offset: offset,
    MaxRecords: 5,
    Fields: ["状态", "日期"],
    Filter: {"criteria": [{
    "field": "状态",
    "op": "Equals",
    "values": ["待付款"]
    }]}
    })
    offset = records.offset
    all = all.concat(records.records)
    }
    console.log(all.length)
    return all
    }

    const recs = fetchAllRecords()
    console.log(recs)