【问题标题】:How do I do a search filtered by date AND time in SuiteScript 2?如何在 SuiteScript 2 中按日期和时间过滤搜索?
【发布时间】:2021-03-30 18:52:34
【问题描述】:

这可行,但只能按日期过滤:

var dt = format.format({type: format.Type.DATE, value: new Date()});
search.create({ type: "supportcase", filters: [['lastmodifieddate', search.Operator.AFTER, dt]], columns: ["internalid"] }).run().getRange(0, 1000);

但这会导致 UNEXPECTED_ERROR:

var dt = format.format({type: format.Type.DATETIME, value: new Date()});
search.create({ type: "supportcase", filters: [['lastmodifieddate', search.Operator.AFTER, dt]], columns: ["internalid"] }).run().getRange(0, 1000);

format.Type.DATETIMETZ 也会导致 UNEXPECTED_ERROR。

日期不够,我需要按日期和时间过滤。

搜索 UI 允许按日期和时间过滤 lastmodifieddate:

在 NS 工作了几年后,我不应该对这有多困难感到失望,但我确实如此。

【问题讨论】:

  • 如果搜索运算符和字段的组合支持添加时间,请检查搜索 UI。上次修改日期和创建日期允许时间,而开始日期似乎不允许。
  • @Brian 确实如此,请参阅更新后的问题

标签: datetime filter netsuite suitescript2.0


【解决方案1】:

这是 SS2 中最愚蠢的事情之一。

您不能在日期时间搜索中使用 NS 格式的 DATETIME。我用这个:

function toNSSearchableDatetime(date) {
    var formatted = format.format({ value: date, type: format.Type.DATETIMETZ });
    return formatted.replace(/(:\d{2}):\d{1,2}\b/, '$1');
}

那么

search.create({ type: "supportcase",
  filters: [['lastmodifieddate', search.Operator.AFTER, toNSSearchableDatetime(date)]], 
  columns: ["internalid"] 
}).run().getRange(0, 1000);

【讨论】:

    【解决方案2】:

    浏览器插件将销售订单的类似搜索转换为以下搜索。不知道为什么它使用两个日期:

    var salesorderSearchObj = search.create({
       type: "salesorder",
       filters:
       [
          ["type","anyof","SalesOrd"], 
          "AND", 
          ["lastmodifieddate","after","3/30/2021 12:00 am","3/30/2021 2:20 pm"]
       ],
       columns:
       [
          search.createColumn({name: "tranid", label: "Document Number"}),
          search.createColumn({name: "lastmodifieddate", label: "Last Modified"})
       ]
    });
    

    【讨论】:

      猜你喜欢
      • 2022-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2013-10-20
      • 1970-01-01
      相关资源
      最近更新 更多